Skip to content

chore: adopt ruff 0.16 — 1631 typing fixes, verified against Python 3.9 - #39

Merged
VickyXAI merged 2 commits into
mainfrom
chore/adopt-ruff-0.16
Jul 28, 2026
Merged

chore: adopt ruff 0.16 — 1631 typing fixes, verified against Python 3.9#39
VickyXAI merged 2 commits into
mainfrom
chore/adopt-ruff-0.16

Conversation

@VickyXAI

Copy link
Copy Markdown
Contributor

#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 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 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 applied the fixes.

Verified, not assumed

Check Result
union syntax outside annotations (cast(), TypeAlias, isinstance) none — every union is in an annotation
compileall under a real Python 3.9.21 exit 0
test suite 436 pass
types.py (pydantic, resolves string annotations) checked by import and suite

The 227 remaining are behaviour, not typing

Ignored with a written reason each, not silently:

  • BLE001 (157) blind except Exception — several are deliberate best-effort paths (telemetry, cleanup) where raising would be worse. Which ones has to be read case by case.
  • S110 / S112 (54) try/except/pass and continue — same question.
  • DTZ005 / DTZ006 (4) naive datetimes in 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.
  • RUF012 (2) mutable class defaults, both in examples/ and tests/.

Two one-offs got a targeted fix, not a blanket ignore

  • the example file is now executable (EXE001)
  • x != x carries # noqa: PLR0124 — x!=x is the NaN test, which it is. I checked before "fixing" it.

1bcMax 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.
@VickyXAI
VickyXAI merged commit 7682f9f into main Jul 28, 2026
4 checks passed
@VickyXAI
VickyXAI deleted the chore/adopt-ruff-0.16 branch July 28, 2026 05:49
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