chore: adopt ruff 0.16 — 1631 typing fixes, verified against Python 3.9 - #39
Merged
Conversation
added 2 commits
July 27, 2026 22:40
#36 pinned ruff at 0.14.11 because 0.16 reported 1903 findings and turning CI green by absorbing them silently would have been the wrong move. This is that change, made on purpose. The trap was real. 1529 of the fixes are classified UNSAFE, and this package declares requires-python = ">=3.9" — PEP 604 (`X | None`) is a runtime error there. Applying them blind would have broken the published 3.9 support while every test passed on 3.13. What made them safe was the rule ruff was already pointing at: FA100, 341 occurrences of "this file could use `from __future__ import annotations`". With that import every annotation is a string, so PEP 585/604 syntax never executes. Added to the 16 files that lacked it, THEN the fixes applied. Verified rather than assumed: - grepped for union syntax outside annotations — cast(), TypeAlias, isinstance(). None. Every union is in an annotation, where laziness applies. - compiled the whole package under a real Python 3.9.21. Exit 0. - 436 tests pass. types.py is pydantic, which resolves string annotations, so that one was checked by import as well as by suite. The 227 remaining findings are behaviour, not typing, and are ignored with a written reason each rather than silently: 157 blind excepts where some are deliberate best-effort paths, 54 try/except/pass, and 4 naive datetimes in cache/tx_log/wallet. That last one is worth doing — a transaction log without a timezone is genuinely ambiguous — but it changes recorded values and needs its own migration thought. Two one-offs got a targeted fix instead of a blanket ignore: the example file is now executable, and `x != x` carries a noqa saying it is the NaN test, which it is.
…ons at runtime CI on Python 3.9 caught what my local check did not: TypeError: Unable to evaluate type annotation 'str | None' `from __future__ import annotations` makes annotations strings, which is what made the PEP 604 rewrite safe everywhere else. pydantic then EVALUATES those strings to build each model, and on 3.9 evaluating "str | None" is a TypeError regardless of how it got there. My verification was wrong in a specific way worth naming: I ran compileall under a real 3.9 and it passed, because parsing is not the constraint — evaluation is. Nothing that only parses the file can catch this. types.py goes back to typing.Optional/List with no future import, and carries a per-file ruff ignore saying why. The other 15 files are unaffected: they have no runtime annotation reader. Now verified by running, not compiling: a real 3.9.21 venv with the package installed passes 339 tests, and 3.13 passes 436.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#36 pinned ruff at
0.14.11because 0.16 reported 1903 findings, and turning CI green by absorbing them silently would have been the wrong move. This is that change, made on purpose.The trap was real
1529 of the fixes are classified UNSAFE, and this package declares
requires-python = ">=3.9". PEP 604 (X | None) is a runtime error on 3.9.Applying them blind would have broken published 3.9 support while every test passed on 3.13.
What made them safe
The rule ruff was already pointing at:
FA100, 341 occurrences of "this file could usefrom __future__ import annotations". With that import every annotation is a string, so PEP 585/604 syntax never executes.Added to the 16 files that lacked it → then applied the fixes.
Verified, not assumed
cast(),TypeAlias,isinstance)compileallunder a real Python 3.9.21types.py(pydantic, resolves string annotations)The 227 remaining are behaviour, not typing
Ignored with a written reason each, not silently:
except Exception— several are deliberate best-effort paths (telemetry, cleanup) where raising would be worse. Which ones has to be read case by case.try/except/passandcontinue— same question.cache.py,tx_log.py,wallet.py. Worth fixing — a transaction log without a timezone is genuinely ambiguous — but it changes recorded values and needs its own migration thought.examples/andtests/.Two one-offs got a targeted fix, not a blanket ignore
EXE001)x != xcarries# noqa: PLR0124 — x!=x is the NaN test, which it is. I checked before "fixing" it.