-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pyright can't resolve same-directory imports when having a pyproject.toml
and a .pth
file.
#9610
Comments
Quick followup to note that it also happens with folder imports. To the above example I add folder echo "/home/rgoya/pyright_test" > $CONDA_PREFIX/lib/python3.*/site-packages/pyright_test.pth
mkdir ~/pyright_test/
cd ~/pyright_test/
mkdir org
echo 'baz = "Baz!"' > org/bar.py
echo -e "import bar\n\nprint(bar.baz)" > org/foo.py
mkdir org/qux
echo 'baz = "Baz in qux.bar!"' > org/qux/bar.py
echo -e "import qux.bar\n\nprint(qux.bar.baz)" > org/foo_qux.py Then we run the tests: $ cd ~/pyright_test/
$ find .
.
./org
./org/foo_qux.py
./org/qux
./org/qux/bar.py
./org/bar.py
./org/foo.py
$ python org/foo.py
Baz!
$ python org/foo_qux.py
Baz in qux.bar!
$ pyright .
0 errors, 0 warnings, 0 informations
$ # Let's trigger the bug
$ echo -e "[tool.pyright]\nexclude = []" > pyproject.toml
$ pyright .
/home/rgoya/pyright_test/org/foo.py
/home/rgoya/pyright_test/org/foo.py:1:8 - error: Import "bar" could not be resolved (reportMissingImports)
/home/rgoya/pyright_test/org/foo_qux.py
/home/rgoya/pyright_test/org/foo_qux.py:1:8 - error: Import "qux.bar" could not be resolved (reportMissingImports)
2 errors, 0 warnings, 0 informations
$ # ... and back
$ rm pyproject.toml
$ pyright .
0 errors, 0 warnings, 0 informations
$ # ... and removing pyright_test.pth instead, re-establish bug
$ echo -e "[tool.pyright]\nexclude = []" > pyproject.toml
$ pyright . # sanity check for failure
/home/rgoya/pyright_test/org/foo.py
/home/rgoya/pyright_test/org/foo.py:1:8 - error: Import "bar" could not be resolved (reportMissingImports)
/home/rgoya/pyright_test/org/foo_qux.py
/home/rgoya/pyright_test/org/foo_qux.py:1:8 - error: Import "qux.bar" could not be resolved (reportMissingImports)
2 errors, 0 warnings, 0 informations
$ # remove pth file... which we require so it's not an option for us
$ rm $CONDA_PREFIX/lib/python3.*/site-packages/pyright_test.pth
$ pyright .
0 errors, 0 warnings, 0 informations |
Thanks for the bug report. I'm able to repro this. @rchiodo, this looks to be a regression related to your Uri changes from earlier in the year. In particular, it came in through this pylance pull request. It looks like the logic for @rgoya, strictly speaking, this import should fail to resolve because the ".pth" is pointing to |
I believe @heejaechang made this change. This commit here on our side: I assume it was to fix a problem with imports in a standalone file? |
Thanks for reviewing, @erictraut! Unfortunately both your suggestions are not easily doable in our environment. The codebase is in a mono repo shared with several dozen developers, data scientists, and other user types. The two main folders are a large "production" code folder (let's call it
Having the Modifying Going back to 1.1.365 behaviour would be ideal. That said, on our side we are also considering enforcing long form imports on |
Describe the bug
Having a
pyproject.toml
and a.pth
file stops pyright from resolving absolute imports from the same directory as the importing file. (Step 6 in import resolution order)Reproduce the bug
(Edit: I've added full repro code in followup #9610 (comment))
Consider a folder structure like so:
Contents of
pyright_test/org/bar.py
are:Contents of
pyright_test/org/foo.py
are:There is also a
pyright_test.pth
file in~/.conda/lib/python3.*/site-packages
that contains:At this point things seem fine:
I then create a file
pyright_test/pyproject.toml
to add some pyright configurations:The actual contents don't seem to matter, as long as
[tool.pyright]
is there, the bug is triggered:If I remove either the
pyproject.toml
or thepyright_test.pth
file, pyright works again.pyright CLI version
👍 In versions 1.1.365 and prior (tested 351, 361, 365) having both
pyproject.toml
andpyright_test.pth
causes no problems.👎 Starting in version 1.1.366 and forward (tested 366, 370, 383, 391) having both
pyproject.toml
andpyright_test.pth
triggers the bug.Debug traces
Last working version (1.1.365):
Bug in latest version (1.1.391)
The text was updated successfully, but these errors were encountered: