You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
support platform and version checks in conditional expressions #5671
I wanted to write os.environb if sys.version_info[0] == 3 else os.environ to obtain a dictionary of bytes environmental variables. However, this fails to typecheck on Python 2 because mypy doesn't recognize the version in conditional expressions.
We do support platform and version checks, but only sys.platform and sys.version_info. Considering six is used a fair amount for Python2/3 straddling code, I think we should also support it.
import sys
import os
reveal_type(os.environb if sys.version_info > (3, 0, 0) else os.environ)
This reveals builtins.object on Python 3 and gives an attribute error on Python 2 (since os.environb doesn't exist). This does indeed seem to be a bug.
Activity
emmatyping commentedon Sep 25, 2018
We do support platform and version checks, but only
sys.platformandsys.version_info. Consideringsixis used a fair amount for Python2/3 straddling code, I think we should also support it.benjaminp commentedon Sep 25, 2018
Ah, sorry, I didn't mean this to be about
six. There's the same problem withsys.version_info[0] == 3.emmatyping commentedon Sep 25, 2018
Ah, interesting, with this:
This reveals
builtins.objecton Python 3 and gives an attribute error on Python 2 (sinceos.environbdoesn't exist). This does indeed seem to be a bug.gvanrossum commentedon Sep 25, 2018
(OT:
six.PY3support is easy: just pass--always-true=PY3.)ilevkivskyi commentedon Sep 26, 2018
This is a duplicate of #5550.
I will raise the priority of that issue (but still not high probably, since there is a simple workaround).