I've got two PRs up right now which pretty significantly enhance Twisted's type annotations in two core areas: FilePath and Deferred.

In FilePath's case, things were previously entirely un-annotated.  With the PR I have up, FilePath is now generic, i.e. FilePath[str] or FilePath[bytes] so you can clearly see what the type of `.path` (and friends) are and get proper type checking.  I'm writing some FilePath intensive code in an application right now and this is really handy and has caught several minor bugs for me already.  (And because I've gotta make CI happy, this includes ZipPath…)


For Deferreds, there are just a bunch of places where type-checking silently fails; for example, addCallback and addErrback don't check their arguments at all.  Perhaps more saliently to modern code, Deferred.fromFuture() wasn't specializing its result, so you'd lose all type-checking across an asyncio boundary.  And maybeDeferred() just returned a nonsense result of Deferred[Deferred] so it was effectively unusable.


Both are passing tests, have full coverage, and have had at least a little bit of feedback, so they should be relatively easy reviews.  If you've got some application code that you would like to type-check against these to see if they spot any bugs for you, that would be great, but if we I could get these approved, this type of comprehensive type-safety upgrade would make a nice tentpole for our first 2023 release.

-g