-
Notifications
You must be signed in to change notification settings - Fork 767
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
Go to Definition always opens up stub .pyi
file even .py
file exists
#6015
Comments
.pyi
file even .py
file exists
I just tried and it worked as expected with latest pylance prerelease bit. Can you provide us some logs as described in the troubleshooting guide? |
maybe double check you've selected to correct python environment |
hello @bschnurr, the python interpreter should be correct, I'm using the please find attached pylance logs: my test file is : |
can we see what you get when you run
missing something like this
which is where the source file should exist. I see |
(.venv 3.11) 00:18 $ which python
/home/xiang/git/fastapi-demo/.venv/bin/python
(.venv 3.11) 00:18 $ python
Python 3.11.7 (main, Jan 13 2024, 23:46:53) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/xiang/opt/python3.11/lib/python311.zip', '/home/xiang/opt/python3.11/lib/python3.11', '/home/xiang/opt/python3.11/lib/python3.11/lib-dynload', '/home/xiang/git/fastapi-demo/.venv/lib/python3.11/site-packages']
>>> the file |
more info about the python interpreters, and one more question, the last (.venv 3.11) 00:29 $ ll /bin/python*
lrwxrwxrwx 1 root root 7 Apr 15 2020 /bin/python -> python2*
lrwxrwxrwx 1 root root 14 Apr 15 2020 /bin/python-config -> python2-config*
lrwxrwxrwx 1 root root 9 Mar 13 2020 /bin/python2 -> python2.7*
lrwxrwxrwx 1 root root 16 Mar 13 2020 /bin/python2-config -> python2.7-config*
-rwxr-xr-x 1 root root 3662000 Jan 31 17:23 /bin/python2.7*
lrwxrwxrwx 1 root root 33 Jan 31 17:23 /bin/python2.7-config -> x86_64-linux-gnu-python2.7-config*
lrwxrwxrwx 1 root root 9 Mar 13 2020 /bin/python3 -> python3.8*
lrwxrwxrwx 1 root root 16 Mar 13 2020 /bin/python3-config -> python3.8-config*
lrwxrwxrwx 1 root root 41 Apr 1 2022 /bin/python3.10 -> /home/xiang/opt/python3.10/bin/python3.10*
lrwxrwxrwx 1 root root 41 Jan 13 23:49 /bin/python3.11 -> /home/xiang/opt/python3.11/bin/python3.11*
lrwxrwxrwx 1 root root 41 May 1 14:10 /bin/python3.12 -> /home/xiang/opt/python3.12/bin/python3.12*
-rwxr-xr-x 1 root root 5465880 Nov 22 2023 /bin/python3.8*
lrwxrwxrwx 1 root root 33 Nov 22 2023 /bin/python3.8-config -> x86_64-linux-gnu-python3.8-config*
lrwxrwxrwx 1 root root 39 Mar 16 2021 /bin/python3.9 -> /home/xiang/opt/python3.9/bin/python3.9*
(.venv 3.11) 00:29 $ which python
/home/xiang/git/fastapi-demo/.venv/bin/python
(.venv 3.11) 00:30 $ deactivate
bash: /home/xiang/.vscode-server/extensions/ms-python.python-2024.8.1/python_files/deactivate/bash/deactivate: Permission denied |
@copdips hmmm.. not sure why we didn't get these 2 paths ( meanwhle, you can put ... @karthiknadig have you seen the permission issue before? I am not sure why |
Thx, this workaround works ! |
@heejaechang |
I dont believe so. I think we need to add some logging to see what we got from calling ... can you set make sure |
here is the log with |
I might found the cause, but I dont know why. In fact, under the root of my project, I have the file [tool.pyright]
venvPath = "."
venv = ".venv" removing this conf makes everyting working again. I need this conf as explained here. |
so, unfortunately, if you provide explicit location to the so, probably the |
it's weird, why specifying venv path in pyright conf prevents it from finding the the real source for stdlib ? .venv 3.11) 00:18 $ which python
/home/xiang/git/fastapi-demo/.venv/bin/python
(.venv 3.11) 00:18 $ python
Python 3.11.7 (main, Jan 13 2024, 23:46:53) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> [print(p) for p in sys.path]
/home/xiang/git/fastapi-demo/.venv/bin
/home/xiang/opt/python3.11/lib/python311.zip
/home/xiang/opt/python3.11/lib/python3.11
/home/xiang/opt/python3.11/lib/python3.11/lib-dynload
/home/xiang/git/fastapi-demo/.venv/lib/python3.11/site-packages
>>> From my understanding in Python out of pyright, venv is to specify where the additional libs are installed, not for std libs. Or maybe the |
in normal setup, if we run that said, I think what you want is 2 different settings for |
well, |
my use case requires a slightly more nuanced approach to pre-commit due to 2 scenarios: 1/ in vscode local developement, venv is used. as explained here, I need pre-commit to validate each commit, so the 2/ in CI pipeline, there's no venv involved. All the third party packages are installed directly using the CI's default python interpreter. Before running pre-commit in CI, I dynamically remove the 2 conf lines ( |
how about you do it opposite way? dynamically inserting 2 conf lines for |
personally I can accept some level of hack in CI pipeline, but not in normal development, as other developers should use the same thing. |
then, |
yes but not 100%, as I suppose That means to let it working 100%, I need to set this in the |
@copdips Here's how I handle this issue:
|
@thanhph111 |
Code Snippet
Hello,
go-to-definition
never works as long as.pyi
files exists.For example,
go-to-definition
overgetLogger
in the below example always opens up pyalnce's stub instead of orignal python file:/home/xiang/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/logging/__init__.pyi
I expect it to open up the real source code:
/home/xiang/opt/python3.11/lib/python3.11/logging/__init__.py
If I switch the user settings to
"python.languageServer": "Jedi"
, thengo-to-definition
works, but unfortunately, I lost all the Pylance's features.The text was updated successfully, but these errors were encountered: