Skip to content

Commit e8a4b58

Browse files
authored
typing(build[ty]): Check package, tests, and docs with ty (#567)
why: Root CI omitted vendored version-parser modules that the local type recipe checked explicitly, and mypy rejected valid runtime negative-test and Sphinx domain patterns across the package, tests, and docs. what: - Replace mypy with locked ty checks across src/, tests/, and docs/ on Python 3.11 and 3.15 while keeping Ruff ANN signature rules enabled - Separate raw and sortable PEP 440 local version segments in libvcs._vendor.version - Narrow dataclass, byte/text regex, generator lock, and Sphinx Python domain types across src/libvcs/ and docs/conf.py - Scope negative-test ty directives in tests/ and document the open-type input boundary policy in AGENTS.md Closes #566
2 parents 968636a + c427bb0 commit e8a4b58

30 files changed

Lines changed: 156 additions & 371 deletions

‎.augment-guidelines‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The project uses the following tools and technologies:
1010
- **ruff** - Fast Python linter and formatter
1111
- **py.test** - Testing framework
1212
- **pytest-watcher** - Continuous test runner
13-
- **mypy** - Static type checking
13+
- **ty** - Static type checking
1414
- **doctest** - Testing code examples in documentation
1515

1616
### Development Workflow
@@ -43,7 +43,7 @@ The project uses the following tools and technologies:
4343
4. **Run Linting and Type Checking**
4444
```
4545
uv run ruff check . --fix --show-fixes
46-
uv run mypy
46+
uv run ty check
4747
```
4848

4949
5. **Verify Tests Again**

‎.cursor/rules/dev-loop.mdc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The project uses the following tools and technologies:
1414
- **ruff** - Fast Python linter and formatter
1515
- **py.test** - Testing framework
1616
- **pytest-watcher** - Continuous test runner
17-
- **mypy** - Static type checking
17+
- **ty** - Static type checking
1818
- **doctest** - Testing code examples in documentation
1919

2020
## 1. Start with Formatting
@@ -62,7 +62,7 @@ uv run ruff check . --fix --show-fixes
6262
Check typings:
6363

6464
```
65-
uv run mypy
65+
uv run ty check
6666
```
6767

6868
## 5. Verify Tests Again

‎.github/CONTRIBUTING.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ Lint:
4444
$ uv run ruff check . --fix --show-fixes
4545
```
4646

47-
[mypy](http://mypy-lang.org/) runs in strict mode (`[tool.mypy] strict =
48-
true`):
47+
[ty](https://docs.astral.sh/ty/) checks the package, tests and documentation. Ruff checks function signatures.
4948

5049
```console
51-
$ uv run mypy .
50+
$ uv run ty check
5251
```
5352

5453
Test:

‎.github/workflows/tests.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ jobs:
4747
- name: Format with ruff
4848
run: uv run ruff format . --check
4949

50-
- name: Lint with mypy
51-
run: uv run mypy .
50+
- name: Check types with ty
51+
run: |
52+
uv run ty check --python-version "${{ matrix.python-version }}"
53+
uv run ruff check --select ANN001,ANN002,ANN003,ANN201,ANN202,ANN204,ANN205,ANN206 src/libvcs/_vendor/*.py
5254
5355
- name: Print python versions
5456
run: |

‎.vim/coc-settings.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"python.analysis.useLibraryCodeForTypes": true,
88
"python.formatting.provider": "ruff",
99
"python.linting.ruffEnabled": true,
10-
"python.linting.mypyEnabled": true,
1110
"python.linting.flake8Enabled": false,
1211
"python.linting.pyflakesEnabled": false,
1312
"python.linting.pycodestyleEnabled": false,

‎.windsurfrules‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- ruff - Fast Python linter and formatter
66
- py.test - Testing framework
77
- pytest-watcher - Continuous test runner
8-
- mypy - Static type checking
8+
- ty - Static type checking
99
- doctest - Testing code examples in documentation
1010
</project_stack>
1111

‎AGENTS.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ was asked for.
2222
| `docs/` | Sphinx (MyST) site; build with `just build-docs` |
2323
| `CHANGES` | Changelog; rendered as the docs changelog page |
2424
| `README.md` | Project overview; listed in `testpaths` (see below) |
25-
| `justfile` | Task runner for tests, lint, mypy, and docs |
25+
| `justfile` | Task runner for tests, lint, ty, and docs |
2626

2727
## Which policy applies
2828

@@ -48,6 +48,23 @@ stated twice, the file listed above is the one that governs.
4848
- A passing gate is evidence only once it has been shown capable of failing.
4949
Pair a new test with a deliberate break that proves it bites.
5050

51+
## Python typing
52+
53+
Give callers the most precise signature that covers supported behavior. Use
54+
`object` for a parameter only when every value is valid or when the function
55+
accepts unknown input for validation. Narrow unknown values before using them.
56+
Reserve `Any` for an inherently dynamic interface where Python cannot express
57+
the input contract. Explain the reason there and keep unchecked values out of
58+
the rest of the API.
59+
60+
Before weakening a type, inspect real callers and try a precise alternative.
61+
A union can describe known alternatives, a protocol can name the operations a
62+
caller must provide, and a type parameter can preserve the relationship between
63+
an input and its result. Try both a supported call and a plausible misuse with
64+
ty. Check what downstream callers infer, whether the error is understandable,
65+
and whether existing valid calls still work. Never widen a type, cast a value,
66+
or suppress a diagnostic solely to make the checker pass.
67+
5168
## Domain facts
5269

5370
- `pyproject.toml` runs `--doctest-docutils-modules` over

‎CHANGES‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ $ uv add libvcs --prerelease allow
2020
_Notes on the upcoming release will go here._
2121
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->
2222

23+
The package, tests and Sphinx configuration now run through ty. Version ordering, regular-expression matching and VCS command behavior retain their existing runtime contracts. ([#567](https://github.com/vcs-python/libvcs/pull/567))
24+
2325
### Breaking changes
2426

2527
#### `Git.version` returns a parsed `Version` (#491)

‎docs/conf.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import typing as t
88

99
if t.TYPE_CHECKING:
10-
from docutils import nodes # type: ignore[import-untyped]
10+
from docutils import nodes
1111
from sphinx import addnodes
1212
from sphinx.application import Sphinx
13-
from sphinx.domains.python import PythonDomain
1413
from sphinx.environment import BuildEnvironment
1514

1615
from gp_sphinx.config import make_linkcode_resolve, merge_sphinx_config
@@ -78,11 +77,14 @@ def _on_missing_class_reference(
7877
) -> nodes.reference | None:
7978
if node.get("refdomain") != "py" or node.get("reftype") != "class":
8079
return None
80+
from sphinx.domains.python import PythonDomain
8181
from sphinx.util.nodes import make_refnode
8282

83-
py_domain: PythonDomain = env.get_domain("py") # type: ignore[assignment]
83+
py_domain = env.get_domain("py")
84+
if not isinstance(py_domain, PythonDomain):
85+
return None
8486
target = node.get("reftarget", "")
85-
matches = py_domain.find_obj(env, "", "", target, None, 1) # type: ignore[attr-defined,unused-ignore]
87+
matches = py_domain.find_obj(env, "", "", target, None, 1)
8688
if not matches:
8789
return None
8890
_name, obj_entry = matches[0]

‎docs/project/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Tests, documentation builds, formatting, and linting.
2222
:::{grid-item-card} Code Style
2323
:link: code-style
2424
:link-type: doc
25-
Ruff, mypy, NumPy docstrings, import conventions.
25+
Ruff, ty, NumPy docstrings, import conventions.
2626
:::
2727

2828
:::{grid-item-card} Releasing

0 commit comments

Comments
 (0)