Skip to content

Installed stubs not always taking precedence in PEP 561 implementation #4876

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

Closed
JukkaL opened this issue Apr 9, 2018 · 3 comments
Closed

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 9, 2018

I installed a package with inline type annotations using python setup.py install and installed the corresponding stubs package using python setup.py install --user. Mypy picked up the inline type annotations instead of the stubs, even though I'd expect that a stub package takes precedence. I suspect that this is caused by the package and the stubs being in different directories, and that the order in which we search through the directories may affect which types will be used by mypy.

@ethanhs Can you take a look at this?

@gvanrossum
Copy link
Member

gvanrossum commented Apr 9, 2018 via email

@JukkaL
Copy link
Collaborator Author

JukkaL commented Apr 9, 2018

I guess either approach could be okay, as long as it's clearly documented. Also, it would be good to have a way for mypy to print out the full search path, in case mypy isn't finding the expected stubs/annotations. mypy -v could be modified to do this, for example.

@emmatyping
Copy link
Member

The PEP is not specific here (see the section about this https://www.python.org/dev/peps/pep-0561/#type-checker-module-resolution-order), perhaps it should be. I think within the category of "installed packages" it shouldn't matter where they are installed. I have a simple patch which should fix this. (PR incoming)

emmatyping added a commit to emmatyping/mypy that referenced this issue Apr 9, 2018
Due to the method of looking for installed packages, it was possible for
the search to be unstable: an installed inline package would be chosen
before an installed stub package. This corrects that by storing a
seperate list for each, and putting the stub packages first.

Fixes python#4876
gvanrossum pushed a commit that referenced this issue Apr 9, 2018
Due to the method of looking for installed packages, it was possible for
the search to be unstable: an installed inline package would be chosen
before an installed stub package. This corrects that by storing a
seperate list for each, and putting the stub packages first.

Fixes #4876
sizmailov added a commit to sizmailov/mypy that referenced this issue Jan 6, 2021
WIP-1
Few more fixes for issues found by testing on internal codebases (python#4876)

Few unrelated (but quite obvious) fixes here.

Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants