-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Document version/system/implementation checks that tools might want to support #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What would |
I originally wrote it without thinking, by way of comparison to
|
Also |
Since 3.3, there is |
Right now, version branches are barely used, so I'd start with something simple. |
My vote goes to starting with the simplest possible rules that cover the (hopefully vast) majority of cases first, and once we have more experience we can decide to incrementally make it more general. There is always going to be an endless number of weird corner cases that are very rare and probably not worth supporting because of the added complexity. |
PEP 484 declares that the following should be supported:
Unfortunately mypy doesn't support these yet. (See python/mypy#698) |
See also discussion in python#17.
* Use less strict IO[str] instead of TextIO * IO[Any] should be IO[str] See also discussion in #17.
Mypy now supports sys.version_info and sys.platform (and they are now heavily used in typeshed). |
A tool takes as input a python version, host system, python implementation, and body of python code, and returns a set of errors. Some tools may also support querying the type of an expression (e.g. for autocompletion of its attributes in an IDE).
How many and how finely it supports the platform checks, and whether it allows running checks for platforms other than the one it is currently running (simultaneously or in a separate run), is a QoI issue - this document nearly. However, tools should not make it impossible to check Windows-specific code from a Linux host.
At the very least, most tools will want to support python2 vs python3 detection.
Here's my list of branches that should be followed:
assert
andif
statements with comparisons (==
,!=
,<
,>
,<=
,>=
; possibly chained likex < y < z
), andand
,not
, andor
expressions containing only comparisons, which contain only literals (of typestr
,int
, ortuple
of literals) and the following:platform.python_version()
platform.python_version_tuple()
sys.version
sys.version_info
sys.hexversion
platform.python_implementation()
platform.system()
sys.platform
maybe? (icky for e.g.linux2
vslinux
)...
" would require changing many stubs that currently usex = ('', 0)
as a short form ofx = ... # type: Tuple[str, int]
.six
stub via the above.else
andelif
branches following the above (not thatelif
need not have such an expression)if string_literal [not] in sys.modules
maybe? Needs justification.try ... except ImportError
try ... except AttributeError
where the object is a module.try ... except NameError
for builtins e.g.unicode
andlong
.The text was updated successfully, but these errors were encountered: