Skip to content
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

Allow installing stub packages in mypy's Python as a fallback #5651

Open
ilevkivskyi opened this issue Sep 20, 2018 · 6 comments
Open

Allow installing stub packages in mypy's Python as a fallback #5651

ilevkivskyi opened this issue Sep 20, 2018 · 6 comments

Comments

@ilevkivskyi
Copy link
Member

Currently PEP 561 specifies that stub packages (like sqlalchemy-stubs) should be installed in the site packages of the Python version of the program that is being checked:

Type checkers that check a different Python version than the version they run on MUST find the type information in the site-packages/dist-packages of that Python version.

However, there is an important use case for stub packages that is incompatible with such path resolution scheme: single installation for stubs accompanied by a plugin. For example, all large frameworks like Django, NumPy, SQLAlchemy, etc. require both stubs and mypy plugins to properly type-check code using them. Ideally, a user should be able to just pip install them (stubs and mypy plugin) in one place, which is the place where mypy is installed.

What I propose is to add a sentence like (approximately): "If the package is not found in that version, it is searched in the version of Python where the type checker is running."

@ethanhs What do you think?

NOTE: Currently this accidentally works in mypy. I propose to make this an officially supported feature, and add proper support to mypy.

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 21, 2018

Hm, this makes me feel a bit uneasy. There are cases where this might not be possible (e.g. a Python 2 only dependency).

I would much rather have mypy look in the other Python executable for the plugin than have mypy break the model of "We look at the Python executable pointed at via python_executable or python_version for typed packages".

@gvanrossum
Copy link
Member

That was my POV too, but Ivan's argument was that then you'd to execute two pip commands (using two different interpreters!) to install the typing support for such packages. That has much more of a chance of breaking, since it's likely that some kind of coordination between versions of the plugin and the stubs is needed.

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 21, 2018

@gvanrossum but if we search for plugins based on python_executable the package only needs to be installed in the correct Python install AFAICT?

@ilevkivskyi
Copy link
Member Author

Also there seems to be some misunderstanding about what I am proposing:
a) I don't want to change anything about typed packages either inline or with stubs, since those contain actual runtime code, I am talking only about stub packages (number 3 in PEP 561 resolution order).
B) I don't want it as a default behavior, we still look in the dedicated version, but if we didn't find it, we fall back to the current version of Python.

@ilevkivskyi
Copy link
Member Author

@ethanhs
A plugin is actual runtime code that will be executed by the interpreter, it may be even syntactically invalid for Python 2. On the other hand, stub files are essentially just text.

@ethanhs
Copy link
Collaborator

ethanhs commented Oct 5, 2018

I suppose I am okay with this. It makes me feel uneasy, but I can't disagree that it has good ergonomic benefits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants