Skip to content

fix(ruff): move typing-only imports into TYPE_CHECKING blocks for py314 - #190

Merged
BenPinet merged 2 commits into
nextfrom
fix/ruff_py314
Oct 21, 2026
Merged

BenPinet merged 2 commits into
nextfrom
fix/ruff_py314

Conversation

@MaxNumerique

Copy link
Copy Markdown
Contributor

Why

Since Geode-solutions/actions@70242614 ("move web to Python 3.14"), the prepare job rewrites ruff.toml to target-version = "py314" on every PR branch. Python 3.14 evaluates annotations lazily (PEP 649), so with select = ["ALL"] ruff now reports every import used only in annotations:

  • TC001: 39 first-party imports
  • TC002: 13 third-party imports
  • TC003: 35 standard library imports

ruff check --fix in CI can't fix them because ruff marks these fixes as unsafe. As a result, every web PR that gets the prepare commit fails the lint job (e.g. #188).

How

  • ruff.toml: target-version = "py314" (what prepare would set anyway).
  • ruff check --fix --unsafe-fixes . then ruff format . (ruff 0.17.1, same as CI). Imports used only in annotations move under if TYPE_CHECKING:. Also fixes 2 UP043.
  • No logic changes. 41 files, mostly tests (Callable, ServerMonitor).

Ruff marks these fixes unsafe because they break code that reads annotations at runtime. Checked:

  • typed_rpc.py: Route / Callable are only used in annotations; route.params / route.response are attribute accesses.
  • dataclasses_json resolves field types with get_type_hints, but the generated dataclasses live in **/schemas/**, which ruff excludes, so none of them were touched.

Verification (Python 3.14)

  • ruff check . → all checks passed, ruff format --check . → clean
  • mypy (strict, mypy.ini) → no issues in 227 source files
  • pytest → 224 passed. 4 errors were server-startup TimeoutErrors. On rerun, tests/test_viewer_protocols.py and the 2 other affected files pass (19 + 20 passed).

🤖 Generated with Claude Code

The prepare job now sets ruff target-version to py314. With PEP 649
lazy annotations, ruff flags imports only used in annotations
(TC001/TC002/TC003). Apply ruff unsafe fixes repo-wide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxNumerique
MaxNumerique requested a review from BotellaA October 21, 2026 12:42
@BenPinet
BenPinet merged commit ef7202f into next Oct 21, 2026
30 checks passed
@BenPinet
BenPinet deleted the fix/ruff_py314 branch October 21, 2026 13:37
@JulienChampagnol

Copy link
Copy Markdown
Member

🎉 This PR is included in version 1.35.0-rc.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@geode-ci

geode-ci Bot commented Oct 22, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.35.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@geode-ci geode-ci Bot added the released label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants