> On May 7, 2020, at 1:56 PM, Craig Rodrigues <rodr...@crodrigues.org> wrote:
> 
> 
> 
> On Wed, Apr 22, 2020 at 12:28 AM Glyph <gl...@twistedmatrix.com 
> <mailto:gl...@twistedmatrix.com>> wrote:
> 
> 
>> On Apr 21, 2020, at 8:57 PM, Craig Rodrigues <rodr...@crodrigues.org 
>> <mailto:rodr...@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 
> <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 
> <https://github.com/twisted/twisted/pull/1264>  (has no attribute "skip")
> https://github.com/twisted/twisted/pull/1261 
> <https://github.com/twisted/twisted/pull/1261> (Too few arguments to 
> "makeTestCaseClasses")

Thank you for doing this work, Craig!  I strongly suspect that mypy is going to 
spot more than a few real bugs in our codebase, and I can think of at least one 
enthusiastic user (me) who wants Twisted to start shipping stubs for our users 
to use!

This also reminded me to file https://twistedmatrix.com/trac/ticket/9816#ticket 
<https://twistedmatrix.com/trac/ticket/9816#ticket> because i couldn't find it 
filed already.

-glyph

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to