-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Stop suggesting MYPYPATH on missing imports #5950
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
Stop suggesting MYPYPATH on missing imports #5950
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Here are some suggestions.
docs/source/running_mypy.rst
Outdated
2. Reading the :ref:`finding-imports` section below to make sure you | ||
understand how exactly mypy searches for and finds modules and modify | ||
how you're invoking mypy accordingly. | ||
3. Adding the path to that module to the ``MYPYPATH`` environment variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"path to that module" -> "directory containing that module (or containing its outermost ancestor package, if the module occurs in a package)"
(Not sure about the wording but I want to make sure people get that for a module inside a package they should add the directory containing the outermost package, not the name of the module or the name of its immediate parent package.)
|
||
1. Searching to see if there is a :ref:`PEP 561 compliant stub package <installed-packages>`. | ||
corresponding to your third party library. Stub packages let you install | ||
type hints independently from the library itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give a real-world example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an innocuous-looking one: https://pypi.org/project/ordered-set-stubs/
docs/source/running_mypy.rst
Outdated
:ref:`import discovery <config-file-import-discovery-per-module>` in config files. | ||
|
||
3. To silence *all* missing import errors for *all* libraries in your codebase, | ||
invoke mypy with the ``--ignore-missing-imports`` command line flag. We |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also mention the equivalent config option?
@gvanrossum -- thanks for the feedback! I made all of the changes you suggested, except for the one about adding an example of a stubs package. There's some discussion about this on gitter, but the long and short of it was that I wasn't really able to find an example of a PEP 561 stubs package I felt entirely comfortable using. I'm thinking of waiting until sqlalchemy-stubs is published on PyPI and submitting a PR that uses that as an example. Alternatively, I could submit a PR to typeshed or something containing a list of PEP 561 packages and link to that instead? That might require more coordination with @ethanhs + the typeshed folks though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG! Adding ordered-set-stubs as example is optional.
|
||
1. Searching to see if there is a :ref:`PEP 561 compliant stub package <installed-packages>`. | ||
corresponding to your third party library. Stub packages let you install | ||
type hints independently from the library itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an innocuous-looking one: https://pypi.org/project/ordered-set-stubs/
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 steps to try for each case.
It also modifies the docs to suggest that users try searching for or writing their stubs first and try silencing errors second.
Resolves #5241.