microsoft / pyright

Static Type Checker for Python
Other
13.04k stars 1.39k forks source link

Fix issue with cwd not being used to find the python interpreter paths #8364

Closed rchiodo closed 1 month ago

rchiodo commented 1 month ago

Addresses https://github.com/microsoft/pyright/issues/8367

It seems it's not necessary to remove the cwd for the sys or os modules. They can't be overridden by local versions and our existing code already excluded the cwd when finding other modules.

I tested this by:

Our interpreter search code is this:

import sys
import os, os.path
normalize = lambda p: os.path.normcase(os.path.normpath(p))
cwd = normalize(os.getcwd())
orig_sys_path = [p for p in sys.path if p != ""]
sys.path[:] = [p for p in sys.path if p != "" and normalize(p) != cwd]
json.dump(dict(path=orig_sys_path, prefix=sys.prefix), sys.stdout)

Running that code does not load the custom json module though.

github-actions[bot] commented 1 month ago

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] commented 1 month ago

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅