[Twisted-Python] twistedchecker now uses pylint >= 2.4.4, can we use type annotations in Twisted now?

Craig Rodrigues rodrigc at crodrigues.org
Thu May 7 14:56:35 MDT 2020


On Wed, Apr 22, 2020 at 12:28 AM Glyph <glyph at twistedmatrix.com> wrote:

>
>
> On Apr 21, 2020, at 8:57 PM, Craig Rodrigues <rodrigc at crodrigues.org>
> wrote:
>
> Does anyone else have opinions on
> type hints and mypy?
>
>
> We use them at work, and on some other Twisted projects (Klein) and
> they're absolutely awesome.  Even with type comments, mypy is a huge
> upgrade to how one writes and maintains Python; with annotations, it's a
> major upgrade to the language.
>
> The first step here, however, is to set up the CI infrastructure (tox,
> etc) to run mypy so that we can ensure that as we start writing type hints,
> we don't accidentally get any of them wrong and back ourselves into any
> corners.  Mypy can catch a surprising number of bugs with just the implicit
> type-checking it does on values that come from the standard library.  In
> fact, if we do `mypy src/twisted` right now, and exclude the things that
> would be fixed by adding in https://github.com/Shoobx/mypy-zope ("method
> must have at least one argument" zope.interface definition errors) and
> fixing up some simple type hints (has no attribute "skip") we still have
> almost a thousand type errors that we should figure out a way to start
> correcting or systematically skipping if they're false positives.  I
> guarantee you there's at least one real bug in there though.
>
> As you know, I tend to be pretty cautious about sweeping changes to the
> code that might make it harder to maintain on older versions - type hints
> are an exception where I think it's absolutely worthwhile to go All In
> early on.  But CI infrastructure for this stuff is a must-have and it might
> be tricky to get set up initially.
>



Earlier this week, I merged to trunk a new tox rule for running mypy with
mypy-zope.  You can use it by
running the following command in the top-level Twisted directory:

*tox -e  mypy*

mypy reports a lot of errors, but I think we can take several passes
through the Twisted codebase to clean those up.

Once we clean up the errors, we can integrate the tox rule with Travis or
Azure CI or CircleCI (whatever works best).

I submitted a few PR's to start cleaning up these errors:

   - https://github.com/twisted/twisted/pull/1264  (has no attribute "skip")
   - https://github.com/twisted/twisted/pull/1261 (Too few arguments to
   "makeTestCaseClasses")

--
Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20200507/49c3a30a/attachment.htm>


More information about the Twisted-Python mailing list