[Python-ideas] Proposal to extend PEP 484 (gradual typing) to support Python 2.7

Guido van Rossum guido at python.org
Fri Jan 22 14:24:13 EST 2016


On Fri, Jan 22, 2016 at 11:19 AM, Random832 <random832 at fastmail.com> wrote:

> On Fri, Jan 22, 2016, at 14:08, Guido van Rossum wrote:
> > In mypy (and in typeshed and in typing.py), 'str' refers to the typenamed
> > str in the Python version for which you are checking -- i.e. by default
> > mypy checks in PY3 mode and str will be the unicode type; but "mypy
> --py2"
> > checks in PY2 mode and str will be the Python 2 8-bit string type. (This
> > is actually the only thing that makes sense IMO.)
>
> Why should it need to check both modes separately? Does it not work at a
> level where it can see if the expression that a value originates from is
> "native" (e.g. a literal with no u/b) or bytes/unicode?
>

There are many differences between PY2 and PY3, not the least in the stubs
for the stdlib. If you get an expression by calling a built-in function (or
anything else that's not a literal) the type depends on what's in the stub.
The architecture of mypy just isn't designed to take two different sets of
stubs (and other differences in rules, e.g. whether something's an iterator
because it defines '__next__' or 'next') into account at once.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160122/034415d2/attachment.html>


More information about the Python-ideas mailing list