-
Notifications
You must be signed in to change notification settings - Fork 770
Description
Summary
Enhance the just check-typing recipe to include ruff check --select ANN,UP alongside the existing ty check, making it easier for contributors to validate type annotations locally before pushing.
This was suggested by @bblommers in PR #1838 and aligns with the typed subset initiative in #1839.
Current State
justfile check-typing recipe
Currently only runs ty check with many --ignore flags:
ty check \
--python "${VENV_PATH}/bin/python" \
--ignore unresolved-import \
--ignore unresolved-attribute \
--ignore unresolved-reference \
--ignore possibly-missing-attribute \
--ignore call-non-callable \
--ignore invalid-assignment \
--ignore invalid-argument-type \
--ignore invalid-method-override \
--ignore invalid-type-form \
--ignore unsupported-operator \
--ignore too-many-positional-arguments \
--ignore unknown-argument \
--ignore not-subscriptable \
--ignore not-iterable \
--ignore no-matching-overload \
--ignore conflicting-declarations \
src/autobahn/Missing: ruff check --select ANN,UP for annotation presence and modern syntax.
CI workflow (main.yml)
The quality-checks job runs:
just check-format cpy314— ruff formatting/lintingjust check-typing cpy314— ty type checking
Once we update the check-typing recipe, CI will automatically pick up the changes.
Proposed Changes
1. Add ruff annotation checks to check-typing
# Add before ty check:
echo "==> Checking type annotation presence and style (via ruff)..."
ruff check --select ANN,UP,TCH src/autobahn/
echo "==> Running static type checks (via ty)..."
ty check ...Rule sets:
| Rule | Purpose |
|---|---|
ANN |
flake8-annotations — missing type annotations |
UP |
pyupgrade — modernize syntax (Optional → X | None, etc.) |
TCH |
flake8-type-checking — proper TYPE_CHECKING imports |
2. Configure ruff in pyproject.toml
Add/update ruff configuration to match the style guide from #1839:
[tool.ruff]
target-version = "py311"
line-length = 120
[tool.ruff.lint]
select = [
"ANN", # flake8-annotations
"I", # isort
"E", # pycodestyle errors
"F", # pyflakes
"W", # pycodestyle warnings
"UP", # pyupgrade
"TCH", # flake8-type-checking
]
[tool.ruff.lint.flake8-annotations]
mypy-init-return = true
suppress-none-returning = false
allow-star-arg-any = false
[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]3. Gradual ignore removal
The current ty check has many --ignore flags with a FIXME comment. As typing coverage improves per #1839, these should be progressively removed:
Phase 1 (now): Add ruff ANN,UP,TCH checks (may need --ignore initially)
Phase 2 (ongoing): As modules get typed, remove corresponding --ignore flags
Phase 3 (goal): Zero ignores — full strict mode
4. Verify CI integration
After updating check-typing, verify that:
-
just check-typing cpy314passes locally - CI
quality-checksjob runs the updated recipe - Any new ruff errors are either fixed or explicitly ignored with inline comments
Implementation Notes
Option A: Strict from the start
- Run
ruff check --select ANN,UP,TCHwithout ignores - Fix all violations before merging
- Cleaner but more work upfront
Option B: Gradual adoption
- Add ruff checks with
--ignorefor specific rules initially - Remove ignores as files are typed
- Matches the "piece by piece" approach
Recommend Option B to avoid blocking on full codebase typing.
Acceptance Criteria
-
just check-typingruns bothruff check --select ANN,UP,TCHandty check -
pyproject.tomlhas ruff configuration matching style guide - CI
quality-checksjob passes with updated recipe - Documentation updated (if any contributor docs exist)
Related
- [FEATURE] Constrain codebase to statically typed and region-based lifetimes Python subset #1839 — Constrain codebase to statically typed Python subset (parent issue)
- Autobahn WebSocket Protocol - Improve typing #1838 — Initial typing contribution by @bblommers (merged)
- [FEATURE] Constraint code base to statically typed Python subset txaio#214 — Same initiative for txaio
References
Checklist
- I have searched existing issues to avoid duplicates
- I have described the problem clearly
- I have provided use cases
- I have considered alternatives
- I have assessed impact and breaking changes