-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Warn about --follow-untyped-imports #18249
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,25 @@ If you are getting this error, try to obtain type hints for the library you're u | |
to the library -- see our documentation on creating | ||
:ref:`PEP 561 compliant packages <installed-packages>`. | ||
|
||
4. Force mypy to analyze the library as best as it can (as if the library provided | ||
a ``py.typed`` file), despite it likely missing any type annotations. In general, | ||
the quality of type checking will be poor and mypy may have issues when | ||
analyzing code not designed to be type checked. | ||
|
||
You can do this via setting the | ||
:option:`--follow-untyped-imports <mypy --follow-untyped-imports>` | ||
command line flag or :confval:`follow_untyped_imports` config file option to True. | ||
This option can be specified on a per-module basis as well:: | ||
|
||
# mypy.ini | ||
[mypy-untyped_package.*] | ||
follow_untyped_imports = True | ||
|
||
# pyproject.toml | ||
[[tool.mypy.overrides]] | ||
module = ["untyped_package.*"] | ||
follow_untyped_imports = true | ||
Comment on lines
+290
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use |
||
|
||
If you are unable to find any existing type hints nor have time to write your | ||
own, you can instead *suppress* the errors. | ||
|
||
|
@@ -295,9 +314,15 @@ not catch errors in its use. | |
all import errors associated with that library and that library alone by | ||
adding the following section to your config file:: | ||
|
||
# mypy.ini | ||
[mypy-foobar.*] | ||
ignore_missing_imports = True | ||
|
||
# pyproject.toml | ||
[[tool.mypy.overrides]] | ||
module = ["foobar.*"] | ||
ignore_missing_imports = true | ||
|
||
Note: this option is equivalent to adding a ``# type: ignore`` to every | ||
import of ``foobar`` in your codebase. For more information, see the | ||
documentation about configuring | ||
|
@@ -311,22 +336,20 @@ not catch errors in its use. | |
|
||
You can also set :confval:`disable_error_code`, like so:: | ||
|
||
# mypy.ini | ||
[mypy] | ||
disable_error_code = import-untyped | ||
|
||
# pyproject.toml | ||
[tool.mypy] | ||
disable_error_code = ["import-untyped"] | ||
|
||
You can also set the :option:`--ignore-missing-imports <mypy --ignore-missing-imports>` | ||
command line flag or set the :confval:`ignore_missing_imports` config file | ||
option to True in the *global* section of your mypy config file. We | ||
recommend avoiding ``--ignore-missing-imports`` if possible: it's equivalent | ||
to adding a ``# type: ignore`` to all unresolved imports in your codebase. | ||
|
||
4. To make mypy typecheck imports from modules without stubs or a py.typed | ||
marker, you can set the :option:`--follow-untyped-imports <mypy --follow-untyped-imports>` | ||
command line flag or set the :confval:`follow_untyped_imports` config file option to True, | ||
either in the global section of your mypy config file, or individually on a | ||
per-module basis. | ||
|
||
|
||
Library stubs not installed | ||
--------------------------- | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.