review needed: better type hints for FilePath, Deferred
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
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…) https://github.com/twisted/twisted/pull/11823 #11822 filepath annotations by glyph · Pull Request #11823 · twisted/twisted github.com 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. https://github.com/twisted/twisted/pull/11770 #11772 Correct deferred annotations by glyph · Pull Request #11770 · twisted/twisted github.com 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
![](https://secure.gravatar.com/avatar/c375e6540d596bde41de8d8c7464eb11.jpg?s=120&d=mm&r=g)
All type hints gratefully received! On 16/03/2023 22:45, Glyph wrote:
I have just kicked off a run of Synapse's CI against the Deferred branch. It is somewhat unhappy [1], but eyeballing the error messages I can believe those are false positives that can be fixed by better annotations in Synapse. In other words: no red flags that I can see. I haven't tried the other branch: as far as I can see (well, grep), we don't use FilePath ourselves. [1]: https://github.com/matrix-org/synapse/actions/runs/4482279504/jobs/788010950... David R -- Copyright © 2023 Element - All rights reserved. The Element name, logo and device are registered trademarks of New Vector Ltd. Registered number: 10873661. Registered in England and Wales. Registered address: 10 Queen Street Place, London, United Kingdom, EC4R 1AG. This message is intended for the addressee only and may contain private and confidential information or material which may be privileged. If this message has come to you in error please delete it immediately and do not copy it or show it to any other person.
![](https://secure.gravatar.com/avatar/c375e6540d596bde41de8d8c7464eb11.jpg?s=120&d=mm&r=g)
All type hints gratefully received! On 16/03/2023 22:45, Glyph wrote:
I have just kicked off a run of Synapse's CI against the Deferred branch. It is somewhat unhappy [1], but eyeballing the error messages I can believe those are false positives that can be fixed by better annotations in Synapse. In other words: no red flags that I can see. I haven't tried the other branch: as far as I can see (well, grep), we don't use FilePath ourselves. [1]: https://github.com/matrix-org/synapse/actions/runs/4482279504/jobs/788010950... David R -- Copyright © 2023 Element - All rights reserved. The Element name, logo and device are registered trademarks of New Vector Ltd. Registered number: 10873661. Registered in England and Wales. Registered address: 10 Queen Street Place, London, United Kingdom, EC4R 1AG. This message is intended for the addressee only and may contain private and confidential information or material which may be privileged. If this message has come to you in error please delete it immediately and do not copy it or show it to any other person.
participants (2)
-
David Robertson
-
Glyph