Skip to content

Enable ruff typing-only import rules (TC) - #773

Draft
anth-volk wants to merge 2 commits into
ruff-safe-autofixesfrom
ruff-typing-imports
Draft

anth-volk wants to merge 2 commits into
ruff-safe-autofixesfrom
ruff-typing-imports

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #772

Same-Repository Draft PR Check

  • This PR is a draft.
  • This PR is from a branch in PolicyEngine/policyengine-sim-api, not a personal fork.

Summary

Phase 1 step 1.8, group 2: typing-only imports. Stacked on #765.

  • What changed: ruff.toml gains TC, and 146 fixes move annotation-only imports under TYPE_CHECKING.
  • What stays at runtime: [lint.flake8-type-checking] lists:
    • Runtime-evaluated base classes: pydantic.BaseModel, pydantic.RootModel, and every project model base class that other models inherit from: 10 across the contract, policyengine-fastapi and executor packages.
    • Runtime-evaluated decorators: the FastAPI/APIRouter route decorators. Pydantic and FastAPI evaluate these annotations at runtime.
  • Shared tool: scripts/rules is byte-identical with policyengine-api.

Testing

All seven projects' test suites pass:

Project Passed
fastapi 14
contract 145
observability 30
stage12 12
entry 224
gateway 214 (includes the OpenAPI golden)
executor 733
  • ruff check . passes with 0.15.22 and 0.16.8, and src formatting is unchanged.
  • Guards and the rules tool unittest pass.

🤖 Generated with Claude Code

@anth-volk
anth-volk added this pull request to stack #755 October 13, 2026 11:40
@anth-volk anth-volk mentioned this pull request Oct 13, 2026
2 tasks done
@anth-volk
anth-volk force-pushed the ruff-typing-imports branch from 18fae4c to f651387 Compare October 13, 2026 16:56
@anth-volk
anth-volk force-pushed the ruff-typing-imports branch 2 times, most recently from 047a2a7 to 26ef5ec Compare October 14, 2026 14:23
anth-volk and others added 2 commits October 14, 2026 18:47
Select TC and move imports used only in annotations under TYPE_CHECKING.
Pydantic evaluates model annotations and FastAPI evaluates endpoint
annotations at runtime, so ruff.toml lists the runtime-evaluated model base
classes (every project base, since ruff only checks direct bases) and the
FastAPI/APIRouter route decorators. scripts/rules matches policyengine-api.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk force-pushed the ruff-typing-imports branch from 26ef5ec to 6c25653 Compare October 14, 2026 14:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant