Skip to content

Commit f905c9d

Browse files
authored
Update linting (#113)
1 parent 2ac92ec commit f905c9d

22 files changed

+213
-166
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ concurrency:
1414

1515
env:
1616
PIP_ROOT_USER_ACTION: ignore
17+
COLUMNS: 200
1718

1819
jobs:
1920
build:

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ _version.py
66
/.python-version
77

88
# Testing
9-
/.coverage
9+
/.coverage*
1010
/coverage.*
11-
/.pytest_cache/
11+
/.*cache/
1212

1313
# Docs
1414
/docs/_build/

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
- id: trailing-whitespace
66
- repo: https://github.com/astral-sh/ruff-pre-commit
7-
rev: v0.1.9
7+
rev: v0.1.11
88
hooks:
99
- id: ruff
1010
args: [--fix, --exit-non-zero-on-fix]
@@ -16,3 +16,11 @@ repos:
1616
additional_dependencies:
1717
- prettier@3.0.2
1818
- prettier-plugin-jinja-template@1.0.0
19+
- repo: https://github.com/pre-commit/mirrors-mypy
20+
rev: v1.8.0
21+
hooks:
22+
- id: mypy
23+
additional_dependencies:
24+
- sphinx
25+
- pytest
26+
- types-docutils

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"python.testing.pytestArgs": ["-v", "--color=yes"],
2+
"python.testing.pytestArgs": ["-vv", "--color=yes"],
33
"python.testing.unittestEnabled": false,
44
"python.testing.pytestEnabled": true,
55
"python.terminal.activateEnvironment": false,
66
"[python]": {
77
"editor.defaultFormatter": "charliermarsh.ruff",
88
"editor.formatOnSave": true,
99
"editor.codeActionsOnSave": {
10-
"source.fixAll": true,
11-
"source.organizeImports": true,
10+
"source.fixAll": "explicit",
11+
"source.organizeImports": "explicit",
1212
},
1313
},
1414
}

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from __future__ import annotations
44

5+
from typing import TYPE_CHECKING
6+
from pathlib import PurePosixPath
57
from datetime import datetime
68
from datetime import timezone as tz
79
from importlib.metadata import metadata
8-
from pathlib import PurePosixPath
9-
from typing import TYPE_CHECKING
1010

1111

1212
if TYPE_CHECKING:

pyproject.toml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ theme = [
4545
[project.entry-points.'sphinx.html_themes']
4646
scanpydoc = 'scanpydoc.theme'
4747

48-
[tool.ruff]
48+
[tool.ruff.lint]
4949
select = ['ALL']
5050
allowed-confusables = ['', '×', 'l']
5151
ignore = [
@@ -57,8 +57,10 @@ ignore = [
5757
'D407', # We’re not using Numpydoc style
5858
'FIX002', # TODOs are OK
5959
'PD', # False positives
60+
'COM812', # Conflicts with formatting
61+
'ISC001', # Conflicts with formatting
6062
]
61-
[tool.ruff.per-file-ignores]
63+
[tool.ruff.lint.per-file-ignores]
6264
'example.py' = ['ALL']
6365
'docs/conf.py' = [
6466
'INP001', # `docs` is not a namespace package
@@ -68,16 +70,25 @@ ignore = [
6870
'D103', # Test functions don’t need docstrings
6971
'S101', # Pytest tests use `assert`
7072
]
71-
72-
[tool.ruff.isort]
73+
[tool.ruff.lint.flake8-type-checking]
74+
strict = true
75+
[tool.ruff.lint.isort]
76+
length-sort = true
7377
lines-after-imports = 2
7478
known-first-party = ['scanpydoc']
7579

80+
[tool.mypy]
81+
strict = true
82+
explicit_package_bases = true
83+
mypy_path = ['$MYPY_CONFIG_FILE_DIR/src']
84+
7685
[tool.hatch.version]
7786
source = 'vcs'
7887
[tool.hatch.build.hooks.vcs]
7988
version-file = 'src/scanpydoc/_version.py'
8089

90+
[tool.hatch.envs.default]
91+
dependencies = ['types-docutils']
8192
[tool.hatch.envs.docs]
8293
python = '3.11'
8394
features = ['doc']
@@ -101,6 +112,19 @@ addopts = [
101112
'-psphinx.testing.fixtures',
102113
]
103114

115+
[tool.coverage.run]
116+
source_pkgs = ["scanpydoc"]
117+
[tool.coverage.paths]
118+
scanpydoc = ["src/scanpydoc"]
119+
[tool.coverage.report]
120+
exclude_lines = [
121+
"no cov",
122+
"if __name__ == .__main__.:",
123+
"if TYPE_CHECKING:",
124+
]
125+
[tool.coverage_rich]
126+
fail-under = 70
127+
104128
[build-system]
105129
requires = ['hatchling', 'hatch-vcs']
106130
build-backend = 'hatchling.build'

src/scanpydoc/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
"""
55
from __future__ import annotations
66

7+
from typing import TYPE_CHECKING, Any, TypeVar
78
from textwrap import indent
8-
from typing import TYPE_CHECKING, Any
9+
from collections.abc import Callable
910

1011
from ._version import __version__
1112

1213

1314
if TYPE_CHECKING:
14-
from collections.abc import Callable
15-
1615
from sphinx.application import Sphinx
1716

1817

@@ -28,9 +27,11 @@
2827
:ref:`Metadata <sphinx:ext-metadata>` for this extension.
2928
"""
3029

30+
C = TypeVar("C", bound=Callable[..., Any])
31+
3132

32-
def _setup_sig(fn: Callable) -> Callable:
33-
fn.__doc__ += "\n\n" + indent(setup_sig_str, " " * 4)
33+
def _setup_sig(fn: C) -> C:
34+
fn.__doc__ = f"{fn.__doc__ or ''}\n\n{indent(setup_sig_str, ' ' * 4)}"
3435
return fn
3536

3637

src/scanpydoc/autosummary_generate_imported.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
from __future__ import annotations
1414

1515
import logging
16-
from pathlib import Path
1716
from typing import TYPE_CHECKING, Any
17+
from pathlib import Path
1818

1919
from sphinx.ext import autosummary
2020
from sphinx.ext.autosummary.generate import generate_autosummary_docs
2121

22-
from . import _setup_sig, metadata
22+
from . import metadata, _setup_sig
2323

2424

2525
if TYPE_CHECKING:
@@ -35,7 +35,7 @@ def _generate_stubs(app: Sphinx) -> None:
3535
if gen_files and not hasattr(gen_files, "__len__"):
3636
env = app.builder.env
3737
gen_files = [
38-
env.doc2path(x, base=None)
38+
env.doc2path(x, base=False)
3939
for x in env.found_docs
4040
if Path(env.doc2path(x)).is_file()
4141
]
@@ -54,9 +54,6 @@ def _generate_stubs(app: Sphinx) -> None:
5454

5555
generate_autosummary_docs(
5656
gen_files,
57-
builder=app.builder,
58-
warn=logger.warning,
59-
info=logger.info,
6057
suffix=suffix,
6158
base_path=app.srcdir,
6259
imported_members=True,

src/scanpydoc/definition_list_typed_field.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
from __future__ import annotations
99

10-
from typing import TYPE_CHECKING
10+
from typing import TYPE_CHECKING, cast
1111

12-
from docutils import nodes
1312
from sphinx import addnodes
13+
from docutils import nodes
1414
from sphinx.domains.python import PyObject, PyTypedField
1515

16-
from . import _setup_sig, metadata
16+
from . import metadata, _setup_sig
1717

1818

1919
if TYPE_CHECKING:
@@ -37,34 +37,31 @@ class DLTypedField(PyTypedField):
3737
#: Override the list type
3838
list_type = nodes.definition_list
3939

40-
def make_field(
40+
def make_field( # type: ignore[override]
4141
self,
4242
types: dict[str, list[nodes.Node]],
4343
domain: str,
4444
items: tuple[str, list[nodes.inline]],
4545
env: BuildEnvironment | None = None,
46-
**kw, # noqa: ANN003
46+
**kw: Any, # noqa: ANN401
4747
) -> nodes.field:
4848
"""Render a field to a documenttree node representing a definition list item."""
4949

5050
def make_refs(
51-
role_name: str,
52-
name: str,
53-
node: type[TextLikeNode],
51+
role_name: str, name: str, node: type[TextLikeNode]
5452
) -> list[nodes.Node]:
5553
return self.make_xrefs(role_name, domain, name, node, env=env, **kw)
5654

5755
def handle_item(
58-
fieldarg: str,
59-
content: list[nodes.inline],
56+
fieldarg: str, content: list[nodes.inline]
6057
) -> nodes.definition_list_item:
6158
term = nodes.term()
6259
term += make_refs(self.rolename, fieldarg, addnodes.literal_strong)
6360

6461
field_type = types.pop(fieldarg, None)
6562
if field_type is not None:
6663
if len(field_type) == 1 and isinstance(field_type[0], nodes.Text):
67-
(text_node,) = field_type # type: nodes.Text
64+
[text_node] = cast(tuple[nodes.Text], field_type)
6865
classifier_content = make_refs(
6966
self.typerolename,
7067
text_node.astext(),

src/scanpydoc/elegant_typehints/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ def x() -> Tuple[int, float]:
4747

4848
from __future__ import annotations
4949

50+
from typing import TYPE_CHECKING, Any
51+
from pathlib import Path
52+
from functools import partial
5053
from collections import ChainMap
5154
from dataclasses import dataclass
52-
from functools import partial
53-
from pathlib import Path
54-
from typing import TYPE_CHECKING, Any
5555

56-
from docutils.parsers.rst import roles
5756
from sphinx.ext.autodoc import ClassDocumenter
57+
from docutils.parsers.rst import roles
5858

59-
from scanpydoc import _setup_sig, metadata
59+
from scanpydoc import metadata, _setup_sig
6060

6161
from .example import example_func
6262

6363

6464
if TYPE_CHECKING:
6565
from collections.abc import Callable
6666

67-
from sphinx.application import Sphinx
6867
from sphinx.config import Config
68+
from sphinx.application import Sphinx
6969

7070

7171
__all__ = ["example_func", "setup"]
@@ -96,12 +96,12 @@ def _init_vars(_app: Sphinx, config: Config) -> None:
9696
raise ValueError(msg)
9797
if config.typehints_defaults is None and config.annotate_defaults:
9898
# override default for “typehints_defaults”
99-
config.typehints_defaults = "braces"
99+
config.typehints_defaults = "braces" # type: ignore[attr-defined]
100100

101101

102102
@dataclass
103103
class PickleableCallable:
104-
func: Callable
104+
func: Callable[..., Any]
105105

106106
__call__ = property(lambda self: self.func)
107107

@@ -124,7 +124,7 @@ def setup(app: Sphinx) -> dict[str, Any]:
124124

125125
from ._autodoc_patch import dir_head_adder
126126

127-
ClassDocumenter.add_directive_header = dir_head_adder(
127+
ClassDocumenter.add_directive_header = dir_head_adder( # type: ignore[method-assign,assignment]
128128
qualname_overrides,
129129
ClassDocumenter.add_directive_header,
130130
)

0 commit comments

Comments
 (0)