On Fri, May 22, 2015 at 9:45 AM, Jim J. Jewett <jimjjewett@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)