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
pyvertst.py:7:12 - error: Import "foobar" could not be resolved (reportMissingImports)
pyvertst.py:4:13 - information: Type of "PY310" is "Literal[True]"
Expected behavior
pyright should not try to do the import based on the version test.
VS Code extension or command-line
command line pyright version 1.1.278
Try the above in a python 3.10 environment.
The text was updated successfully, but these errors were encountered:
This is expected. You cannot use a variable for the conditional. You need to use the sys.version_info >= (3, 10) directly in the if statement.
Pyright (and other type checkers) look for very specific conditional expression forms in the first stage of analysis (the "binder"), which occurs long before the types of any symbols are evaluated.
PEP 484 indicates "type checkers are expected to understand simple version and platform checks" and then gives a few examples. Pyright and all other type checkers support these expression forms.
You'll need to change the above code to the following for it to work in pyright (and other type checkers):
Describe the bug
If you have a conditional import based on the python version, pyright still says the import is missing.
This comes up in pandas-stubs where we have some dependent libraries that are not ready for python 3.11 yet, so we want to conditionally import them.
To Reproduce
pyright reports:
Expected behavior
pyright should not try to do the import based on the version test.
VS Code extension or command-line
command line pyright version 1.1.278
Try the above in a python 3.10 environment.
The text was updated successfully, but these errors were encountered: