-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Stop suggesting MYPYPATH? #5241
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
Comments
Yeah, that suggestion is often not good. It may be the correct thing to do if the user has multiple package roots, however. Also, Here are the various things that the user might do if a module can't be found, in order of desirability:
|
As @msullivan suggested there are few docs on
This is a good list, but too long to show as a note (and sometimes it is hard to diagnose which case applies). Just showing a link as a note would be better.
PEP 561 currently says that the name of stub packages on PyPI is fixed as "The name of the stub package MUST follow the scheme Also there is something missing in PEP 561 I think, it doesn't say whether the name |
Agreed.
There is some gray area here. For example, what if we have stubs for package "foo" that rely on a mypy plugin to be useful, or some mypy type system features that aren't in a PEP yet. These might be in competition with the "official" stubs, which might only rely on features available in the released Another case where this could be a problem if foo-stubs is very slow to update and is way behind the official package, and the owners don't have capacity to review PRs. Does this mean that a fork that makes the stubs up to date would not be accepted on PyPI? Other packages can be forked; this is FOSS after all.
I think that this could be problematic with the above rule, since some owners might not care about static typing enough to upload such a package, even if there is a lot of demand for the stubs. Also, many owners are only doing minimal maintenance for their package and creating stubs could be a lot of work, as we've learned. |
I think PEP 561 should be more clear here and accommodate such use cases. It may be not important right now, but I could imagine possible problems in future with "competing" stub packages for the same library. A potential solution could be to allow names like There is a problem however, what to do if mypy finds more than one installed package that matches
Yes, but with current version of the PEP, and more importantly its implementation, such package is not recognised by mypy as containing stubs for "foo". |
I suppose this could be included in the PEP, but I feel like it is more a decision to make by the PyPi folks.
This was brought up in the initial discussion of the PEP. I don't think it is an issue. If you don't want to use the |
I'm with Ethan, competing stub packages can have different Distribution names but all install the same Package name (see PEP 561 for term definitions), so the user can choose. |
Also FWIW it seems there is pypi/warehouse#4164 for reserving the names of stub packages on warehouse. |
Ah yes, I am totally fine with this solution. |
Also related to this we should probably stop recommending typeshed for missing stubs as well. |
As a user, I would like to add that getting this message was useful when libraries were in
|
If the module is part of the user's codebase, point MYPYPATH to it.
I like that phrasing. Or perhaps "if it's part of the user's code base but
not in the current directory, ..."
|
This pull request replaces the "Perhaps setting MYPYPATH..." note with a link to https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports It also updates the docs to make that page a little more actionable: it now clearly distinguishes between different scenarios a user might find themselves in, as well as concrete suggestions for each step. It also modifies the docs to suggest that users try searching for or writing their stubs first and try silencing errors second. Resolves python#5241.
This pull request replaces the "Perhaps setting MYPYPATH..." note with a link to https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports It also updates the docs to make that page a little more actionable: it now clearly distinguishes between different scenarios a user might find themselves in and gives concrete suggestions to try for each step. It also modifies the docs to suggest that users try searching for or writing their stubs first and try silencing errors second. Resolves #5241.
Currently whenever mypy fails to find an import it prints a note suggesting to set MYPYPATH, e.g.:
In most cases setting MYPYPATH is an anti-pattern, since the issue is likely that this is a third-party module for which no stubs exist in typeshed (nor anywhere else). We used to see a lot of problems when people added site-packages to MYPYPATH.
Maybe we can add a more nuanced explanation to the docs and link to the docs from the note instead?
The text was updated successfully, but these errors were encountered: