Skip to content

Commit

Permalink
Enable pygrep-hooks in Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 21, 2025
1 parent 46e6046 commit fdd47cf
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ select = [
"LOG", # flake8-logging
# "N", # pep8-naming
"PERF", # perflint
# "PGH", # pygrep-hooks
"PGH", # pygrep-hooks
"PT", # flake8-pytest-style
"TC", # flake8-type-checking
"UP", # pyupgrade
Expand Down
6 changes: 3 additions & 3 deletions breathe/file_state_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def _getmtime(filename: str):

def update(app: Sphinx, source_file: str | os.PathLike[str]) -> None:
if not hasattr(app.env, "breathe_file_state"):
app.env.breathe_file_state = {} # type: ignore
app.env.breathe_file_state = {} # type: ignore[attr-defined]

norm_source_file = Path(source_file).resolve().as_posix()
new_mtime = _getmtime(norm_source_file)
mtime, docnames = app.env.breathe_file_state.setdefault( # type: ignore
mtime, docnames = app.env.breathe_file_state.setdefault( # type: ignore[attr-defined]
norm_source_file, (new_mtime, set())
)

assert app.env is not None
docnames.add(app.env.docname)

app.env.breathe_file_state[norm_source_file] = (new_mtime, docnames) # type: ignore
app.env.breathe_file_state[norm_source_file] = (new_mtime, docnames) # type: ignore[attr-defined]


def _get_outdated(
Expand Down
2 changes: 1 addition & 1 deletion breathe/filetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_pygments_alias(filename: str) -> str | None:
"Find first pygments alias from filename"
try:
lexer_cls = get_lexer_for_filename(filename)
return lexer_cls.aliases[0] # type: ignore
return lexer_cls.aliases[0] # type: ignore[attr-defined]
except ClassNotFound:
return None

Expand Down
2 changes: 1 addition & 1 deletion breathe/finder/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_finder(self, project_info: ProjectInfo) -> Finder:
def create_finder_from_root(self, root, project_info: ProjectInfo) -> Finder:
finders: dict[str, type[ItemFinder]] = {
"doxygen": indexfinder.DoxygenTypeSubItemFinder,
"compound": _CreateCompoundTypeSubFinder(self.app, self.parser_factory), # type: ignore
"compound": _CreateCompoundTypeSubFinder(self.app, self.parser_factory), # type: ignore[dict-item]
"member": indexfinder.MemberTypeSubItemFinder,
"doxygendef": compoundfinder.DoxygenTypeSubItemFinder,
"compounddef": compoundfinder.CompoundDefTypeSubItemFinder,
Expand Down
2 changes: 1 addition & 1 deletion breathe/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, app: Sphinx) -> None:
self.app = app
# TODO: do we have a base class for all the Doxygen XML node types
# that we can use for typing?
self.cache = {} # type: ignore
self.cache = {} # type: ignore[var-annotated]

def create_index_parser(self) -> DoxygenIndexParser:
return DoxygenIndexParser(self.app, self.cache)
Expand Down
4 changes: 2 additions & 2 deletions breathe/renderer/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ def __init__(self, selector: Selector) -> None:
def __call__(self, node_stack):
raise NotImplementedError

def __eq__(self, value: str) -> InFilter: # type: ignore
def __eq__(self, value: str) -> InFilter: # type: ignore[override]
return InFilter(self, [value])

def __ne__(self, value: str) -> NotFilter: # type: ignore
def __ne__(self, value: str) -> NotFilter: # type: ignore[override]
return NotFilter(InFilter(self, [value]))

def is_one_of(self, collection: list[str]) -> InFilter:
Expand Down
14 changes: 7 additions & 7 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from sphinx.util.nodes import nested_parse_with_titles

try:
from sphinxcontrib import phpdomain as php # type: ignore
from sphinxcontrib import phpdomain as php # type: ignore[import-untyped]
except ImportError:
php = None

try:
from sphinx_csharp import csharp as cs # type: ignore
from sphinx_csharp import csharp as cs # type: ignore[import-not-found]
except ImportError:
cs = None

Expand Down Expand Up @@ -67,7 +67,7 @@ class BaseObject:
# Set the content_callback attribute to a function taking a docutils node.

def transform_content(self, contentnode: addnodes.desc_content) -> None:
super().transform_content(contentnode) # type: ignore
super().transform_content(contentnode) # type: ignore[misc]
callback = getattr(self, "breathe_content_callback", None)
if callback is None:
return
Expand Down Expand Up @@ -327,15 +327,15 @@ def create(domain: str, args) -> ObjectDescription:
arg_0 = "global"

if arg_0 in DomainDirectiveFactory.php_classes:
cls, name = DomainDirectiveFactory.php_classes[arg_0] # type: ignore
cls, name = DomainDirectiveFactory.php_classes[arg_0] # type: ignore[assignment]
else:
cls, name = DomainDirectiveFactory.php_classes_default # type: ignore
cls, name = DomainDirectiveFactory.php_classes_default # type: ignore[assignment]

elif cs is not None and domain == "cs":
cls, name = DomainDirectiveFactory.cs_classes[args[0]]
else:
domain = "cpp"
cls, name = DomainDirectiveFactory.cpp_classes[args[0]] # type: ignore
cls, name = DomainDirectiveFactory.cpp_classes[args[0]] # type: ignore[assignment]
# Replace the directive name because domain directives don't know how to handle
# Breathe's "doxygen" directives.
assert ":" not in name
Expand Down Expand Up @@ -599,7 +599,7 @@ def run_directive(
args = [obj_type, [declaration]] + self.context.directive_args[2:]
directive = DomainDirectiveFactory.create(self.context.domain, args)
assert issubclass(type(directive), BaseObject)
directive.breathe_content_callback = contentCallback # type: ignore
directive.breathe_content_callback = contentCallback # type: ignore[attr-defined]

# Translate Breathe's no-link option into the standard noindex option.
if "no-link" in self.context.directive_args[2]:
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ lint = [
"types-docutils",
"types-Pygments",
"pytest>=8.0", # for mypy
"sphinxcontrib-phpdomain", # for mypy
"sphinx-csharp", # for mypy
]
test = [
"pytest>=8.0",
Expand Down Expand Up @@ -93,6 +95,13 @@ exclude = [
]

[tool.mypy]
files = [
"breathe",
"examples",
"tests",
]
show_column_numbers = true
show_error_context = true
python_version = "3.9"
warn_unused_configs = true
warn_redundant_casts = true
Expand Down

0 comments on commit fdd47cf

Please sign in to comment.