[Python-Dev] Status of PEP 484 and the typing module

Guido van Rossum guido at python.org
Fri May 22 18:54:45 CEST 2015


On Fri, May 22, 2015 at 9:45 AM, Jim J. Jewett <jimjjewett at gmail.com> wrote:

>
>
> Mark Shannon wrote:
>
> > PY2, etc. really need to go.
> > Assuming that this code type checks OK:
> >
> >  if typing.PY2:
> >      type_safe_under_py2_only()
> >  else:
> >      type_safe_under_py3_only()
> >
> > Is the checker supposed to pass this:
> >
> >  if sys.hexversion < 0x03000000:
> >      type_safe_under_py2_only()
> >  else:
> >      type_safe_under_py3_only()
> >
> > If it should pass, then why have PY2, etc. at all.
>
> My immediate response was that there really is a difference,
> when doing the equivalent of cross-compilation.  It would
> help to make this explicit in the PEP.
>

That seems obvious. There's no reason why a type checker should care about
what sys.*version* is in the process that runs the type checker (that
process may not even be a Python interpreter).


> But ...
> > If it should fail, well that is just stupid and annoying.
>
> so I'm not sure regular authors (as opposed to typing tools)
> would ever have reason to use it, and making stub files more
> different from regular python creates an attractive nuisance
> bigger than the clarification.
>
> So in the end, I believe PY2 should merely be part of the calling
> convention for type tools, and that may not be worth standardizing
> yet.  It *is* worth explaining why they were taken out, though.
>

Because there is no advantage (either to the user or to the type checker)
of using e.g. typing.WINDOWS instead of using sys.platform == "win32".


> And it is worth saying explicitly that typing tools should override
> the sys module when checking for non-native environments.
>

OK, I am saying it here. People writing type checkers can decide for
themselves what they want to support. (It is already the case that mypy can
check code for conformance with various Python versions, but mypy itself
must always run in Python 3.4 or later.)

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


More information about the Python-Dev mailing list