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:
Creating an os folder and putting an __init__.py in it.
Creating a sys folder and putting an __init__.py in it
Running python, importing sys and os and trying to call the function in the __init__.py
Neither would load my version
Creating a json folder and putting an __init__.py in it.
Python would load this json module though
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.
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:
os
folder and putting an__init__.py
in it.sys
folder and putting an__init__.py
in it__init__.py
json
folder and putting an__init__.py
in it.Our interpreter search code is this:
Running that code does not load the custom json module though.