Skip to content

[CHORE] Add ruff annotation checks to check-typing recipe #1840

@oberstet

Description

@oberstet

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/linting
  • just 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 (OptionalX | 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 cpy314 passes locally
  • CI quality-checks job 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,TCH without ignores
  • Fix all violations before merging
  • Cleaner but more work upfront

Option B: Gradual adoption

  • Add ruff checks with --ignore for 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-typing runs both ruff check --select ANN,UP,TCH and ty check
  • pyproject.toml has ruff configuration matching style guide
  • CI quality-checks job passes with updated recipe
  • Documentation updated (if any contributor docs exist)

Related

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions