Skip to content

Commit f406ade

Browse files
committed
chore(lint): Fix mypy analysis and lint tooling
1 parent 1b79632 commit f406ade

13 files changed

Lines changed: 1489 additions & 1014 deletions

File tree

.pre-commit-config.yaml

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
repos:
2-
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
# Ruff version.
4-
rev: v0.9.4
5-
hooks:
6-
# Run the linter.
7-
- id: ruff
8-
types_or: [ python, pyi ]
9-
args: [ --fix, --config=pyproject.toml ]
10-
stages: [ pre-commit, manual ]
11-
# Run the formatter.
12-
- id: ruff-format
13-
types_or: [ python, pyi ]
14-
args: [ --config=pyproject.toml ]
15-
stages: [ pre-commit, manual ]
16-
- repo: https://github.com/pre-commit/mirrors-mypy
17-
rev: v1.14.1
18-
hooks:
19-
- id: mypy
20-
args: [ --config-file=pyproject.toml ]
21-
additional_dependencies:
22-
- types-python-dateutil
23-
- types-setuptools
24-
- types-toml
25-
- types-typed-ast
26-
- types-orjson
27-
files: "src/.*"
28-
stages: [ pre-commit, manual ]
29-
- repo: https://github.com/compilerla/conventional-pre-commit
30-
rev: v4.0.0
31-
hooks:
32-
- id: conventional-pre-commit
33-
stages: [commit-msg]
34-
args: []
35-
- repo: https://github.com/astral-sh/uv-pre-commit
36-
# uv version.
37-
rev: 0.5.26
38-
hooks:
39-
- id: uv-sync
40-
args: ["--locked", "--all-packages"]
41-
stages:
42-
- pre-commit
43-
- post-checkout
44-
- post-merge
45-
- post-rewrite
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.13.0
5+
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
types_or: [python, pyi]
9+
args: [--fix, --config=pyproject.toml]
10+
stages: [pre-commit, manual]
11+
# Run the formatter.
12+
- id: ruff-format
13+
types_or: [python, pyi]
14+
args: [--config=pyproject.toml]
15+
stages: [pre-commit, manual]
16+
- repo: https://github.com/pre-commit/mirrors-mypy
17+
rev: v1.18.1
18+
hooks:
19+
- id: mypy
20+
args: [--config-file=pyproject.toml]
21+
additional_dependencies:
22+
- types-python-dateutil
23+
- types-setuptools
24+
- types-toml
25+
- types-typed-ast
26+
- types-orjson
27+
files: "src/.*"
28+
stages: [pre-commit, manual]
29+
- repo: https://github.com/compilerla/conventional-pre-commit
30+
rev: v4.2.0
31+
hooks:
32+
- id: conventional-pre-commit
33+
stages: [commit-msg]
34+
args: []
35+
- repo: https://github.com/astral-sh/uv-pre-commit
36+
# uv version.
37+
rev: 0.8.17
38+
hooks:
39+
- id: uv-sync
40+
args: ["--locked", "--all-packages"]
41+
stages:
42+
- pre-commit
43+
- post-checkout
44+
- post-merge
45+
- post-rewrite

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN_PREFIX := uv run --
1010
# region: environment
1111

1212
quickstart: setup-uv install ## Bootstrap your local environment for development.
13-
.PHONY: bootstrap
13+
.PHONY: quickstart
1414

1515
setup-uv: ## Set up your poetry installation and ensure it's up-to-date.
1616
@curl -LsSf https://astral.sh/uv/install.sh | sh

pyproject.toml

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ dependencies = [
3434
"importlib_metadata >=7.1.0,<8; python_version < '3.10'",
3535
]
3636
[project.optional-dependencies]
37-
json = [
38-
"orjson ~= 3.4",
39-
]
37+
json = ["orjson ~= 3.4"]
38+
4039
[project.urls]
4140
Repository = "https://github.com/seandstewart/typelib"
4241
Homepage = "https://seandstewart.github.io/python-typelib/latest/"
@@ -48,9 +47,9 @@ dev = [
4847
{ include-group = "lint" },
4948
{ include-group = "test" },
5049
"orjson ~= 3.4",
51-
"tox",
5250
"hatch-vcs",
5351
"git-cliff>=2.8.0",
52+
"ipykernel>=6.29.5",
5453
]
5554
docs = [
5655
"mkdocs-material[imaging]",
@@ -63,14 +62,8 @@ docs = [
6362
"mkdocs-literate-nav",
6463
"mkdocs-open-in-new-tab",
6564
]
66-
lint = [
67-
"pre-commit",
68-
]
69-
test = [
70-
"pytest",
71-
"pytest-cov",
72-
"pytest-parametrize-suite",
73-
]
65+
lint = ["pre-commit", "pre-commit-uv"]
66+
test = ["pytest", "pytest-cov", "pytest-parametrize-suite"]
7467

7568
[tool.hatch.version]
7669
source = "vcs"
@@ -81,14 +74,10 @@ version_scheme = "no-guess-dev"
8174
[tool.coverage.run]
8275
branch = true
8376
data_file = "coverage.db"
84-
include = [
85-
"src/**/*",
86-
]
77+
include = ["src/**/*"]
8778

8879
[tool.coverage.paths]
89-
source = [
90-
"src/*",
91-
]
80+
source = ["src/*"]
9281

9382
[tool.coverage.report]
9483
skip_empty = true
@@ -109,15 +98,9 @@ exclude_also = [
10998
"class\\s\\w+\\((typing\\.)?Protocol(\\[.*\\])?\\):",
11099
"@(abc\\.)?abstractmethod",
111100
"@(typing\\.)?overload",
112-
".*\\.\\.\\."
113-
]
114-
omit = [
115-
"dist/*",
116-
"tests/*",
117-
"docs/*",
118-
".venv/*",
119-
"benchmark/*",
101+
".*\\.\\.\\.",
120102
]
103+
omit = ["dist/*", "tests/*", "docs/*", ".venv/*", "benchmark/*"]
121104

122105

123106
[tool.ruff.lint]
@@ -131,7 +114,7 @@ extend-select = [
131114
# flake8-simplify
132115
"SIM",
133116
# Future annotation
134-
"FA"
117+
"FA",
135118
]
136119

137120
[tool.ruff.lint.per-file-ignores]
@@ -144,9 +127,7 @@ extra-standard-library = ["typing_extensions", "graphlib"]
144127

145128
[tool.mypy]
146129
mypy_path = "$MYPY_CONFIG_FILE_DIR/src/"
147-
no_namespace_packages = true
148130
python_version = "3.12"
149131
ignore_missing_imports = true
150-
no_strict_optional = true
151132
follow_imports = "silent"
152133
exclude = ".*tests/.*|.*docs/.*"

src/typelib/binding.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def __init__(
209209
"""
210210
self.signature = signature
211211
self.binding = binding
212-
self.varkwd = varkwd
213-
self.varpos = varpos
212+
self.varkwd = varkwd or unmarshals.noop()
213+
self.varpos = varpos or unmarshals.noop()
214214
self.startpos = startpos
215215

216216
def __repr__(self):
@@ -219,7 +219,7 @@ def __repr__(self):
219219
@abc.abstractmethod
220220
def __call__(
221221
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
222-
) -> tuple[P.args, P.kwargs]:
222+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
223223
"""Inspect the given `args` and `kwargs` and unmarshal them.
224224
225225
Args:
@@ -231,7 +231,7 @@ def __call__(
231231
class AnyParamKindBinding(AbstractBinding[P], tp.Generic[P]):
232232
def __call__(
233233
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
234-
) -> tuple[P.args, P.kwargs]:
234+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
235235
# Localize key attributes
236236
binding = self.binding
237237
varpos: unmarshals.AbstractUnmarshaller = self.varpos
@@ -254,7 +254,7 @@ def __call__(
254254
class PosArgsKwargsBinding(AbstractBinding[P], tp.Generic[P]):
255255
def __call__(
256256
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
257-
) -> tuple[P.args, P.kwargs]:
257+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
258258
# Localize key attributes
259259
binding = self.binding
260260
varpos: unmarshals.AbstractUnmarshaller = self.varpos
@@ -275,7 +275,7 @@ def __call__(
275275
class PosKwdKwargsBinding(AbstractBinding[P], tp.Generic[P]):
276276
def __call__(
277277
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
278-
) -> tuple[P.args, P.kwargs]:
278+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
279279
# Localize key attributes
280280
binding = self.binding
281281
varkwd: unmarshals.AbstractUnmarshaller = self.varkwd
@@ -289,7 +289,7 @@ def __call__(
289289
class PosKwdArgsBinding(AbstractBinding[P], tp.Generic[P]):
290290
def __call__(
291291
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
292-
) -> tuple[P.args, P.kwargs]:
292+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
293293
# Localize key attributes
294294
binding = self.binding
295295
varpos: unmarshals.AbstractUnmarshaller = self.varpos
@@ -311,7 +311,7 @@ def __call__(
311311
class PosKwargsBinding(AbstractBinding[P], tp.Generic[P]):
312312
def __call__(
313313
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
314-
) -> tuple[P.args, P.kwargs]:
314+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
315315
# Localize key attributes
316316
binding = self.binding
317317
varkwd: unmarshals.AbstractUnmarshaller = self.varkwd
@@ -325,7 +325,7 @@ def __call__(
325325
class PosKwdBinding(AbstractBinding[P], tp.Generic[P]):
326326
def __call__(
327327
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
328-
) -> tuple[P.args, P.kwargs]:
328+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
329329
# Localize key attributes
330330
binding = self.binding
331331
# Unmarshal the args
@@ -338,7 +338,7 @@ def __call__(
338338
class PosArgsBinding(AbstractBinding[P], tp.Generic[P]):
339339
def __call__(
340340
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
341-
) -> tuple[P.args, P.kwargs]:
341+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
342342
# Localize key attributes
343343
binding = self.binding
344344
varpos: unmarshals.AbstractUnmarshaller = self.varpos
@@ -357,7 +357,7 @@ def __call__(
357357
class PosBinding(AbstractBinding[P], tp.Generic[P]):
358358
def __call__(
359359
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
360-
) -> tuple[P.args, P.kwargs]:
360+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
361361
# Localize key attributes
362362
binding = self.binding
363363
# Unmarshal the args
@@ -368,7 +368,7 @@ def __call__(
368368
class KwdArgsKwargsBinding(AbstractBinding[P], tp.Generic[P]):
369369
def __call__(
370370
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
371-
) -> tuple[P.args, P.kwargs]:
371+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
372372
# Localize the key attributes
373373
binding = self.binding
374374
varpos: unmarshals.AbstractUnmarshaller = self.varpos
@@ -383,7 +383,7 @@ def __call__(
383383
class KwdArgsBinding(AbstractBinding[P], tp.Generic[P]):
384384
def __call__(
385385
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
386-
) -> tuple[P.args, P.kwargs]:
386+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
387387
# Localize the key attributes
388388
binding = self.binding
389389
varpos: unmarshals.AbstractUnmarshaller = self.varpos
@@ -397,7 +397,7 @@ def __call__(
397397
class KwdKwargsBinding(AbstractBinding[P], tp.Generic[P]):
398398
def __call__(
399399
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
400-
) -> tuple[P.args, P.kwargs]:
400+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
401401
binding = self.binding
402402
varkwd: unmarshals.AbstractUnmarshaller = self.varkwd
403403
# Unmarshal the keyword arguments.
@@ -408,7 +408,7 @@ def __call__(
408408
class KwdBinding(AbstractBinding[P], tp.Generic[P]):
409409
def __call__(
410410
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
411-
) -> tuple[P.args, P.kwargs]:
411+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
412412
binding = self.binding
413413
# Unmarshal the keyword arguments.
414414
umkwargs = {k: binding[k](v) if k in binding else k for k, v in kwargs.items()}
@@ -418,7 +418,7 @@ def __call__(
418418
class ArgsKwargsBinding(AbstractBinding[P], tp.Generic[P]):
419419
def __call__(
420420
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
421-
) -> tuple[P.args, P.kwargs]:
421+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
422422
# Localize the key attributes
423423
varpos: unmarshals.AbstractUnmarshaller = self.varpos
424424
varkwd: unmarshals.AbstractUnmarshaller = self.varkwd
@@ -432,7 +432,7 @@ def __call__(
432432
class KwargsBinding(AbstractBinding[P], tp.Generic[P]):
433433
def __call__(
434434
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
435-
) -> tuple[P.args, P.kwargs]:
435+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
436436
# Localize the key attributes
437437
varkwd: unmarshals.AbstractUnmarshaller = self.varkwd
438438
# Unmarshal the keyword arguments.
@@ -443,7 +443,7 @@ def __call__(
443443
class ArgsBinding(AbstractBinding[P], tp.Generic[P]):
444444
def __call__(
445445
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
446-
) -> tuple[P.args, P.kwargs]:
446+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
447447
# Localize the key attributes
448448
varpos: unmarshals.AbstractUnmarshaller = self.varpos
449449
# Unmarshal the positional arguments.
@@ -454,7 +454,7 @@ def __call__(
454454
class PosOrKwdBinding(AbstractBinding[P], tp.Generic[P]):
455455
def __call__(
456456
self, args: tuple[tp.Any], kwargs: dict[str, tp.Any]
457-
) -> tuple[P.args, P.kwargs]:
457+
) -> tuple[P.args, P.kwargs]: # type: ignore[valid-type]
458458
# Localize the key attributes
459459
binding = self.binding
460460
# Unmarshal the positional args.

src/typelib/ctx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class TypeContext(dict[KeyT, ValueT], tp.Generic[ValueT]):
1717
"""A key-value mapping which can map between forward references and real types."""
1818

19-
def get(self, key: KeyT, default: ValueT | DefaultT = None) -> ValueT | DefaultT:
19+
def get(self, key: KeyT, default: ValueT | DefaultT = None) -> ValueT | DefaultT: # type: ignore[assignment]
2020
with contextlib.suppress(KeyError):
2121
return self[key]
2222

src/typelib/graph.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ def get_type_graph(t: type) -> graphlib.TopologicalSorter[TypeNode]:
171171
class TypeNode:
172172
"""A "node" in a type graph."""
173173

174-
type: typing.Any
174+
type: typing.Type | typing.ForwardRef
175175
"""The type annotation for this node."""
176-
unwrapped: typing.Any | None = None
176+
unwrapped: typing.Type | typing.ForwardRef = None # type: ignore[assignment]
177177
"""The unwrapped type annotation for this node."""
178178
var: str | None = None
179179
"""The variable or parameter name associated to the type annotation for this node."""
@@ -185,7 +185,9 @@ def __post_init__(self):
185185
self.unwrapped = self.type
186186

187187

188-
def _level(t: typing.Any) -> typing.Iterable[tuple[str | None, type]]:
188+
def _level(
189+
t: typing.Any,
190+
) -> typing.Iterable[tuple[str | None, type | typing.ForwardRef]]:
189191
args = inspection.args(t)
190192
# Only pull annotations from the signature if this is a user-defined type.
191193
is_structured = inspection.isstructuredtype(t)

0 commit comments

Comments
 (0)