Goto definition goes to stub files instead of actual definitions
Expected behaviour
Goto definition goes to actual code even if types are defined in a stub file
Actual behaviour
Goto definition goes to stub files instead of actual code
Code Snippet / Additional information
from http import HTTPStatus
print(HTTPStatus.GATEWAY_TIMEOUT)
Try goto definition (F12) on either HTTPStatus in line 1 or GATEWAY_TIMEOUT in line 3
Duplicate https://github.com/microsoft/pyright/issues/795
Goto definition on HTTPStatus results include both the .py and .pyi, which is currently the expected result. As discussed in the linked topic on pyright, we have no control on which of the multiple results appears first.
Goto definition on GATEWAY_TIMEOUT results only include the .pyi, which is a bug, it should be able to find it in sources as well but it doesn't right now.
As a suggestion, if you couldn't control the order of displayed results, it would be nice to have an option turn off displaying *.pyi files in all the results as whole or only display results from *.pyi files when there are no *.py files.
@jahan01 Thanks for the suggestion. We're looking into solutions and will update here soon.
Could we have two separate commands like Go To Declaration/Go To Definition for C/C++ in Visual Studio?
Go To Declarationgoes to.hfiles for C/C++, for Python we can go to the.pyifilesGo To Definitiongoes to.cppfiles for C++, for Python we can go to the.pyfiles- If one of the
.pyifile and.pyfile is missing, the other command could still go to the existing file
hello, is this a bug in below gif?

At the moment, that is expected behavior.
I am trying to annotate tqdm. So I did the following:
- Created a file typings/tqdm/__init__.pyi with:
from typing import Any, Generic, Iterable, Iterator, TypeVar
T = TypeVar('T')
class tqdm(Generic[T]):
def __init__(self, iterable: Iterable[T], *args: Any, **kwargs: Any): ...
def __iter__(self) -> Iterator[T]: ...
- Added
"python.analysis.stubPath": "${workspaceFolder}/typings"to .vscode/settings.json
Now when I click on tqdm -> "Go to Definition" on another piece of code (like `from tqdm import tqdm') it jumps straight to the stub file. Also if I try to see the references on "Go to References" the source code is not listed (it was before adding the stub file). Selecting Peek -> "Peek Definition" only display the stub file as well.
I would expect it to show the source code (or at least give an option to it) when clicking "Go to Definition"
This is a major bug. Navigation into stdlib and 3rd party libraries is basically broken. .pyi files are an implementation detail of a typechecker, please don't put them above the real code.
Anybody thought there is an ambiguous meaning between goto definition and goto stubs? My temp solution is to remove .pyi files but is not very smart.
Well alright. Thanks @jakebailey . I was looking thoroughly but didn't use the word "stub" just .pyi ... 😄
So, what about WIP? How is this supposed to work in the future? Is there a plan? is there a blog post about this? anything?
For me this is simply broken atm and it was fine in the past. There could be another shortcut like Shift+Ctrl+Click to Goto the stub. Actual definition should always be first!, no?
I mean I wanna be fair here: You're doing awesome work already and when doing progress things need to break here and there but I'd at least wanna know how to backup.
That default preference for pyi drives me insane as it is killing the entire code browsing experience for any library that happens to keep type hints outside the source files. I do not want to browse the stubs when the source files exist and we clearly need and option to tell it to respect that preference.
Our only luck is that very few libraries decided to put keep type hints in pyi files.
This is a sound solution, your rarely are interested in definition or type stubs at the same time. There should be a separate option to go to either of them.
Could we have two separate commands like
Go To Declaration/Go To Definitionfor C/C++ in Visual Studio?
Go To Declarationgoes to.hfiles for C/C++, for Python we can go to the.pyifilesGo To Definitiongoes to.cppfiles for C++, for Python we can go to the.pyfiles- If one of the
.pyifile and.pyfile is missing, the other command could still go to the existing file
My C/++ years precede the existence of vscode so I do not know what is current behavior on Cmd+click as I would wish to be Go To Definition by default.
There is a slight issue with having two options because what if you do not have a definition and you only have access to the declaration? in that case I suppose it should send you to the only one available
Apparently the UI is bit confused about what is a definition and declaration as I right click on the method and choose "Go To Definition" and instead it opens the in-line preview of the declaration:
This was happened accesing "Go To Definition":

Also having trouble with this. Previously i at least got both the stub and implementation, but now I only get the stub when using F12...
I am also experiencing this issue. My current solution involves renaming my /typings folder whenver I need goto impl. I've had it occasionally recognize both the pyi stub and the library .py implementation, but I have no way of consistently reproducing that behavior. Seems a bit odd that a stub would completely obfuscate the implementation.
Started happening to me today. No workaround for this at least?
We are currently investigating solutions to address this.
I believe a solution here would be the approach Pycharm takes. Providing a clickable widget in the gutter if a corresponding .py or .pyi is available. See screenshots below.


@savannahostrowski any new news on this?