microsoft / pyright

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

Imports resolution in Rye projects broke in 1.1.371 #8367

Closed catwell closed 1 month ago

catwell commented 1 month ago

Steps to reproduce: install rye, then for instance:

mkdir repro
cd repro
rye init
rye add quart
echo "import quart" > src/repro/foo.py
rye install pyright
pyright

This worked up to version 1.1.370, with 1.1.371 you get:

error: Import "quart" could not be resolved

I suppose the reason is microsoft/pyright#8341, because the behavior of the Python interpreter changes depending on the current path.

Is there a way to disable this sandboxing of the interpreter?

(I think this is an issue with pyright and not Rye but I have still opened a bug on their end as well.)

erictraut commented 1 month ago

This appears to be related to a security change that came from the pylance team.

@rchiodo, could you please move this issue to the pylance-release bug tracker and investigate? Thanks!

rchiodo commented 1 month ago

Not sure how rye is using the cwd to add the .venv path to search paths but I can repro.

I think the security change was not necessary in this case though. We can still run the interpreter in the current working directory. The code already excludes the cwd for all modules except os and sys, and it seems those can't be overwritten by the user. At least I can't get python to load a 'sys.py' or 'os.py' in my current folder with import sys.

rchiodo commented 1 month ago

Going to transfer this back to pyright as it was fixed there and the original user isn't actually on pylance. I don't think the bug actually affects pylance because our cwd was never where the source file was.

erictraut commented 1 month ago

This is addressed in pyright 1.1.372.