What changes when FastAPI upgrades its type checker

ProjectsCommunity Digest0 replies

Community DigestMember#1

In “Does FastAPI's own code still pass the type checker it adopted?”, Alex Georgiev compares two versions of Astral's ty against a FastAPI checkout. His write-up describes the diagnostic changes and the effect of measuring watch mode separately from fresh processes. The original experiment is at https://dev.to/alexgeorgiev17/does-fastapis-own-code-still-pass-the-type-checker-it-adopted-33o7.

Compare diagnostics in the same environment

Georgiev reports one diagnostic with ty 0.0.78, the version pinned in the checkout he examined, and 17 with ty 1.0.0. The common diagnostic was an unresolved import of a companion package missing from his environment. Some of the new diagnostics concerned renamed rules in suppression comments, while three flagged narrower types on writable attributes inherited from a base class.

A writable attribute creates an obligation in both directions. For example, if a base class lets callers assign any integer to an attribute, a subclass that promises a Boolean there cannot enforce that promise through an annotation alone. A caller using the base-class interface can still assign an integer. Astral's rule reference describes this check and lists its introduction after the beta pin reported in the article. See https://docs.astral.sh/ty/reference/rules/#incompatible-mutable-override.

For a checker upgrade, that difference gives reviewers something more actionable than a total count. Keep the checkout and installed dependencies fixed, then group new messages by rule and affected code. A renamed ignore comment calls for a different review from a writable attribute whose declared type changed in a subclass.

Measure the wait that developers actually experience

Georgiev reports about 210 to 250 milliseconds for a fresh ty invocation and 32 to 38 milliseconds for a recheck after adding a blank line to a core FastAPI file while the watcher was running. The watch number measures feedback after startup for that edit in his environment. Astral documents that watch mode rechecks affected files, including files that depend on the changed file. See https://docs.astral.sh/ty/type-checking/.

A team evaluating the upgrade can record fresh-process timings for CI and run a separate set of edits for local feedback. The lockfile and diagnostic diff then show what would change in CI, while the watched edits show how long contributors wait during the local edit cycle.

No replies yet