Skip to content

Commit

Permalink
Enable more lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Dec 3, 2023
1 parent 2c86ce7 commit 9b829be
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .tools/copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_commit: 7d6f4ceea
_commit: 8ebfc313a
_src_path: gh:oprypin/py-project-template
copyright_date: '2020'
mkdocs: true
Expand Down
2 changes: 1 addition & 1 deletion mkdocstrings_handlers/crystal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion mkdocstrings_handlers/crystal/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}")

Expand Down
4 changes: 2 additions & 2 deletions mkdocstrings_handlers/crystal/deduplicate_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -39,4 +39,4 @@ def extendMarkdown(self, md: Markdown) -> None:
)


makeExtension = DeduplicateTocExtension
makeExtension = DeduplicateTocExtension # noqa: N816
26 changes: 18 additions & 8 deletions mkdocstrings_handlers/crystal/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions mkdocstrings_handlers/crystal/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 14 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,26 @@ 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]
allow-dict-calls-with-keyword-arguments = true
[tool.ruff.lint.isort]
known-third-party = ["mkdocstrings"]

[tool.mypy]
warn_unreachable = true
Expand Down

0 comments on commit 9b829be

Please sign in to comment.