at main
2 folders
7 files
Let imports say what they are for, and names say what they are (#603)
Three rules that the tree nearly satisfied already, and one repair to the
gate that had to come first.
`TC` moves the 313 imports that only a type checker reads under
`if TYPE_CHECKING`. `ICN` imports a well-known package under the alias
everyone writes, 190 of them. `N812` retires an alias that disguised what a
name was: 83 places wrote `from ._layout import fiche_paragraph as
Paragraph`, which made a helper of this package read as the class reportlab
publishes under that name. Four conformance domains imported numpy a second
time inside a function that already had it at module scope.
`INP` and `T20` are selected and find nothing. Both are already clean in
`src` and are here to hold it; a print is what the scripts are for, so they
and the tests are exempt.
The clip freshness gate had to be repaired before any of this could land.
It hashes the AST of the code that draws each clip, and its own preamble
says an alarm nobody believes would be worse than no alarm, because a false
positive costs a several-minute re-render. It hashed each reached module
whole, so moving an import under `if TYPE_CHECKING` read as a change to the
drawing even though nothing in that block exists while a frame renders: it
marked most of the forty-two clips stale. It skips those blocks now, and
hashes the remaining imports as a sorted set so that sorting them is not a
change either. It still hashes them, because the walk stops at the package
boundary and for `import numpy as np` the statement is all it has.
`TC006` is not selected. It quotes the first argument of `typing.cast`,
which is never evaluated for its value, so the rewrite is inert; it moved
two clips through `figures.media._save_animation`. Reverting it needs care:
an unquoted cast does evaluate the name, so where a cast names an import
that lives only under `if TYPE_CHECKING`, the quotes are what keep it from
raising. Ruff says so itself as TC004, on seven sites here.
Say the types in half the test suite (#628)
* Say the types in half the test suite
The library, its scripts and its gates are fully annotated; the suite
was the last corner where a parameter arrived nameless. This half
covers the building, materials, room, emission and psychoacoustics
trees: pytest's own plumbing typed with pytest's own types, every
parametrize argument typed from the values really in its list, and
every fixture and helper from what its body builds, read against the
library signature it calls rather than guessed.
Annotations cannot change what a test does, and the full suite agrees:
the same 9402 tests pass before and after.
* Let the language test say what it reads off a result
The factory was typed as returning object, which claims the test never
looks inside, and calling plot is the whole test. A three-line protocol
says exactly as much as the test needs, no more: the shared plot seam
with its language keyword. A union of the six concrete types would have
repeated the parametrize list.