DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
http://docs.basedpyright.com/
Other
601 stars 12 forks source link

`sys.version_info` checks inside imported modules are incorrectly evaluated using that module's `pythonVersion` instead of the `pythonVersion` from the execution environment that's importing it #416

Open DetachHead opened 2 weeks ago

DetachHead commented 2 weeks ago
[tool.basedpyright]
pythonVersion = "3.8"
reportUnusedImport = false

[[tool.basedpyright.executionEnvironments]]
root = "foo"
pythonVersion = "3.9"
# main.py
from typing import Sequence # no error because Sequence is not deprecated in 3.8

print("".removesuffix) # error because removesuffix doesn't exist in 3.8
# foo/a.py
from typing import Sequence # error: This type is deprecated as of Python 3.9; use "collections.abc.Sequence"
print("".removesuffix) # error because it thinks this execution environment is in 3.8???
DetachHead commented 2 weeks ago

looks like this is an issue with sys.version_info checks inside stubs (or any file being import). pyright evaluates them in the context of the main execution environment, because ".venv/Lib/site-packages/basedpyright/dist/typeshed-fallback" is not included in the root of that foo execution environment.

partially related: #107