-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Ignoring a file with a single # type: ignore comment. #6830
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
Changes from 2 commits
7a51cf2
aa11089
ce54ab4
4567661
c95b98d
07cc315
9937b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,30 @@ The second line is now fine, since the ignore comment causes the name | |
| if we did have a stub available for ``frobnicate`` then mypy would | ||
| ignore the ``# type: ignore`` comment and typecheck the stub as usual. | ||
|
|
||
| A ``# type: ignore`` comment at the top of a module (before any statements, | ||
| including imports or docstrings) has the effect of ignoring the *entire* module. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # type: ignore | ||
| import frobnicate | ||
| frobnicate.start() | ||
|
|
||
| When running mypy with Python 3.8 or later, a ``# type: ignore`` comment | ||
|
||
| anywhere at the top indentation level of a module will skip type checking for | ||
| all remaining lines in the file. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| """Docstring.""" | ||
|
|
||
| import spam # These imports are still checked! | ||
| import eggs | ||
|
|
||
| # type: ignore | ||
| import frobnicate | ||
| frobnicate.start() | ||
|
|
||
| Another option is to explicitly annotate values with type ``Any`` -- | ||
| mypy will let you perform arbitrary operations on ``Any`` | ||
| values. Sometimes there is no more precise type you can use for a | ||
|
|
||
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.
This hardly qualifies as "locally" silencing the checker, so I think it doesn't belong in this section.
I would make it a new section titled "Ignoring a whole file" to be inserted after this section (i.e. just before the section named "Unexpected errors about 'None' and/or 'Optional' types").
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.
I've broken it out, as requested.