Type checking tools for Python 2?

Chris Angelico rosuav at gmail.com
Wed Apr 22 00:52:25 CEST 2015


On Wed, Apr 22, 2015 at 5:33 AM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
> On Tue, Apr 21, 2015 at 2:26 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> Sorry if I jumped the gun on mypy.
>
> Not a problem. I went ahead and installed Python 3.5a4 and mypy. It
> seems to run, but it isn't terribly happy with my Python 2 code. Not
> so much the actual syntax as things like the builtin cmp() function
> and the cPickle module being missing.

Shouldn't be too hard to add a few stub files; cPickle could just
"from pickle import *", and cmp() would take two of Any and return
int, etc. MyPy will, if I've understood the docs correctly, welcome a
patch/pull-request that adds this kind of thing.

Actually, the things I'd most expect problems with are the print
statement and "int/int -> int" division, the latter mainly because
it's so subtle. (The bytes vs unicode distinction is dealt with
already.) But both can be fixed with future directives anyway, so
worst case you just have to help your code come a bit closer to Py3
(and frankly, that's not a bad thing).

ChrisA



More information about the Python-list mailing list