diff --git a/.tools/copier-answers.yml b/.tools/copier-answers.yml index 68a6a58..e7bdad4 100644 --- a/.tools/copier-answers.yml +++ b/.tools/copier-answers.yml @@ -1,4 +1,4 @@ -_commit: 7d6f4ceea +_commit: 8ebfc313a _src_path: gh:oprypin/py-project-template copyright_date: '2020' mkdocs: true diff --git a/mkdocstrings_handlers/crystal/__init__.py b/mkdocstrings_handlers/crystal/__init__.py index ba897eb..25f6d35 100644 --- a/mkdocstrings_handlers/crystal/__init__.py +++ b/mkdocstrings_handlers/crystal/__init__.py @@ -22,7 +22,7 @@ def __init__( source_locations: Mapping[str, str] = {}, **config: Any, ) -> None: - BaseHandler.__init__(self, "crystal", theme, custom_templates) # type: ignore + BaseHandler.__init__(self, "crystal", theme, custom_templates) CrystalCollector.__init__( self, crystal_docs_flags=crystal_docs_flags, source_locations=source_locations ) diff --git a/mkdocstrings_handlers/crystal/collector.py b/mkdocstrings_handlers/crystal/collector.py index 7417618..2395cca 100644 --- a/mkdocstrings_handlers/crystal/collector.py +++ b/mkdocstrings_handlers/crystal/collector.py @@ -30,7 +30,7 @@ try: from mkdocs.exceptions import PluginError except ImportError: - PluginError = SystemExit # type: ignore + PluginError = SystemExit # type: ignore[assignment, misc] log = logging.getLogger(f"mkdocs.plugins.{__name__}") diff --git a/mkdocstrings_handlers/crystal/deduplicate_toc.py b/mkdocstrings_handlers/crystal/deduplicate_toc.py index b08aedf..c64cf4f 100644 --- a/mkdocstrings_handlers/crystal/deduplicate_toc.py +++ b/mkdocstrings_handlers/crystal/deduplicate_toc.py @@ -26,7 +26,7 @@ def _deduplicate_toc(toc: list[dict]) -> None: class _TocDeduplicatingTreeprocessor(Treeprocessor): def run(self, root: etree.Element): try: - toc = self.md.toc_tokens # type: ignore + toc = self.md.toc_tokens # type: ignore[attr-defined] except AttributeError: return _deduplicate_toc(toc) @@ -39,4 +39,4 @@ def extendMarkdown(self, md: Markdown) -> None: ) -makeExtension = DeduplicateTocExtension +makeExtension = DeduplicateTocExtension # noqa: N816 diff --git a/mkdocstrings_handlers/crystal/items.py b/mkdocstrings_handlers/crystal/items.py index db220ad..f324ddf 100644 --- a/mkdocstrings_handlers/crystal/items.py +++ b/mkdocstrings_handlers/crystal/items.py @@ -2,10 +2,21 @@ import abc import collections +import contextlib import dataclasses import re from functools import cached_property -from typing import TYPE_CHECKING, Any, Generic, Iterator, Mapping, Sequence, TypeVar, overload +from typing import ( + TYPE_CHECKING, + Any, + ClassVar, + Generic, + Iterator, + Mapping, + Sequence, + TypeVar, + overload, +) from mkdocstrings.handlers.base import CollectionError @@ -26,7 +37,7 @@ class DocItem(metaclass=abc.ABCMeta): def __init__(self, data: Mapping[str, Any], parent: DocItem | None, root: DocRoot | None): self.data = data self.parent = parent - self.root = root or self # type: ignore + self.root = root or self # type: ignore[assignment] @property def name(self) -> str: @@ -105,10 +116,8 @@ def lookup(self, identifier: str | DocPath) -> DocItem: raise CollectionError(f"{identifier!r} - can't find {name!r}") ret_obj = obj if isinstance(obj, DocAlias): - try: + with contextlib.suppress(CollectionError): obj = self.lookup(str(obj.aliased)) - except CollectionError: - pass assert ret_obj is not None return ret_obj @@ -362,7 +371,7 @@ def args_string(self) -> str: # https://github.com/crystal-lang/crystal/issues/12043 ret = self.data["def"].get("return_type", "") return ret and " : " + ret - return crystal_html.parse_crystal_html(html) # type: ignore + return crystal_html.parse_crystal_html(html) # type: ignore[return-value] @cached_property def location(self) -> DocLocation | None: @@ -420,11 +429,12 @@ class DocMapping(Generic[D]): items: Sequence = () search: Mapping[str, Any] = {} + _empty: ClassVar[DocMapping] def __new__(cls, items: Sequence[D]) -> DocMapping: if not items: try: - empty = cls._empty # type: ignore + empty = cls._empty except AttributeError: cls._empty = empty = object.__new__(cls) return empty @@ -469,7 +479,7 @@ def __add__(self, other: DocMapping) -> DocMapping: return self new = object.__new__(type(self)) new.items = [*self, *other] if self else other.items - new.search = collections.ChainMap(new.search, other.search) # type: ignore + new.search = collections.ChainMap(new.search, other.search) # type: ignore[arg-type] return new def __repr__(self): diff --git a/mkdocstrings_handlers/crystal/renderer.py b/mkdocstrings_handlers/crystal/renderer.py index 0231d4d..56caa03 100644 --- a/mkdocstrings_handlers/crystal/renderer.py +++ b/mkdocstrings_handlers/crystal/renderer.py @@ -52,10 +52,8 @@ def update_env(self, md: Markdown, config: dict) -> None: self._pymdownx_hl = None for ext in md.registeredExtensions: - try: - self._pymdownx_hl = ext.get_pymdownx_highlighter() # type: ignore - except AttributeError: - pass + with contextlib.suppress(AttributeError): + self._pymdownx_hl = ext.get_pymdownx_highlighter() # type: ignore[attr-defined] # Disallow raw HTML. md.preprocessors.deregister("html_block") diff --git a/pyproject.toml b/pyproject.toml index 1e00ca3..27fd1d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,16 +112,20 @@ pip-compile-hashes = false [tool.ruff] line-length = 100 select = [ - "I", - "F", "W", "E", "UP", "YTT", "C4", "DTZ", "FA", "ISC", "PIE", "T20", "RSE", "TCH", - "B002", "B003", "B005", "B007", "B009", "B012", "B013", "B014", "B015", "B018", "B020", "B021", "B023", "B026", "B033", "B034", "B905", + "F", "W", "E", "I", "UP", "YTT", "C4", "DTZ", "T10", "FA", "ISC", "PIE", "T20", "RSE", "TCH", + "N803", "N804", "N805", "N806", "N807", "N815", "N816", "N999", + "B002", "B003", "B005", "B007", "B008", "B009", "B010", "B011", "B012", "B013", "B014", "B015", "B016", "B017", "B018", "B020", "B021", "B022", "B023", "B025", "B026", "B029", "B030", "B031", "B032", "B033", "B034", "B905", "COM818", - "PERF101", - "PGH002", "PGH004", "PGH005", + "G001", "G010", "G202", + "RET502", + "SIM101", "SIM103", "SIM105", "SIM107", "SIM118", "SIM201", "SIM202", "SIM208", "SIM210", "SIM211", "SIM212", "SIM220", "SIM221", "SIM222", "SIM223", "SIM300", "SIM401", "SIM910", + "PGH002", "PGH003", "PGH004", "PGH005", + "PLC", "PLE", + "PLR0124", "PLR0133", "PLR0206", "PLR0402", "PLR1701", "PLR1722", "PLW0120", "PLW0127", "PLW0129", "PLW0131", "PLW0406", "PLW0602", "PLW0603", "PLW0711", "PLW1508", "PLW3301", + "TRY302", "TRY401", "FLY002", - "PLC", "PLE", "PLR0124", "PLR0133", "PLR0206", "PLR0402", "PLR1701", "PLR1722", "PLW0120", "PLW0127", "PLW0129", "PLW0131", "PLW0406", "PLW0602", "PLW0603", "PLW0711", - "RUF001", "RUF005", "RUF007", "RUF010", "RUF013", "RUF100", "RUF200", - "SIM101", "SIM107", "SIM201", "SIM202", "SIM208", "SIM210", "SIM211", "SIM300", "SIM401", "SIM910", + "PERF101", "PERF102", "PERF402", + "RUF001", "RUF005", "RUF007", "RUF008", "RUF009", "RUF010", "RUF011", "RUF013", "RUF015", "RUF016", "RUF100", "RUF200", ] ignore = ["E501", "E731"] [tool.ruff.flake8-comprehensions]