Skip to content

Stop suggesting MYPYPATH on missing imports - #5950

Merged
Michael0x2a merged 3 commits into
python:masterfrom
Michael0x2a:stop-recommending-mypypath
Nov 27, 2018
Merged

Michael0x2a merged 3 commits into
python:masterfrom
Michael0x2a:stop-recommending-mypypath

Conversation

@Michael0x2a

Copy link
Copy Markdown
Collaborator

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.

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.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

Comment thread 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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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/

Comment thread docs/source/running_mypy.rst Resolved
Comment thread 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

Copy link
Copy Markdown
Member

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?

@Michael0x2a

Copy link
Copy Markdown
Collaborator Author

@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.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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/

@Michael0x2a
Michael0x2a merged commit b790539 into python:master Nov 27, 2018
@Michael0x2a
Michael0x2a deleted the stop-recommending-mypypath branch November 27, 2018 16:37
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

Successfully merging this pull request may close these issues.

2 participants