pyright icon indicating copy to clipboard operation
pyright copied to clipboard

Imports resolution in Rye projects broke in 1.1.371

Open catwell opened this issue 1 year ago • 3 comments

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.)

catwell avatar Jul 10 '24 13:07 catwell

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!

erictraut avatar Jul 10 '24 15:07 erictraut

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 avatar Jul 10 '24 16:07 rchiodo

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.

rchiodo avatar Jul 10 '24 17:07 rchiodo

This is addressed in pyright 1.1.372.

erictraut avatar Jul 17 '24 02:07 erictraut