Skip to content

Commit cfd01d9

Browse files
authored
Improve error code disabling documentation (#15841)
Provide a concrete example of what file level comments would look like. Sort text into sections a little better.
1 parent c7d2fa1 commit cfd01d9

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

docs/source/error_codes.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ Silencing errors based on error codes
4343
You can use a special comment ``# type: ignore[code, ...]`` to only
4444
ignore errors with a specific error code (or codes) on a particular
4545
line. This can be used even if you have not configured mypy to show
46-
error codes. Currently it's only possible to disable arbitrary error
47-
codes on individual lines using this comment.
48-
49-
You can also use :option:`--disable-error-code <mypy --disable-error-code>`
50-
to disable specific error codes globally.
46+
error codes.
5147

5248
This example shows how to ignore an error about an imported name mypy
5349
thinks is undefined:
@@ -58,17 +54,17 @@ thinks is undefined:
5854
# definition.
5955
from foolib import foo # type: ignore[attr-defined]
6056
61-
62-
Enabling specific error codes
63-
-----------------------------
57+
Enabling/disabling specific error codes globally
58+
------------------------------------------------
6459

6560
There are command-line flags and config file settings for enabling
6661
certain optional error codes, such as :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`,
6762
which enables the ``no-untyped-def`` error code.
6863

69-
You can use :option:`--enable-error-code <mypy --enable-error-code>` to
70-
enable specific error codes that don't have a dedicated command-line
71-
flag or config file setting.
64+
You can use :option:`--enable-error-code <mypy --enable-error-code>`
65+
and :option:`--disable-error-code <mypy --disable-error-code>`
66+
to enable or disable specific error codes that don't have a dedicated
67+
command-line flag or config file setting.
7268

7369
Per-module enabling/disabling error codes
7470
-----------------------------------------
@@ -107,8 +103,9 @@ still keep the other two error codes enabled. The overall logic is following:
107103

108104
* Individual config sections *adjust* them per glob/module
109105

110-
* Inline ``# mypy: ...`` comments can further *adjust* them for a specific
111-
module
106+
* Inline ``# mypy: disable-error-code="..."`` comments can further
107+
*adjust* them for a specific module.
108+
For example: ``# mypy: disable-error-code="truthy-bool, ignore-without-code"``
112109

113110
So one can e.g. enable some code globally, disable it for all tests in
114111
the corresponding config section, and then re-enable it with an inline

0 commit comments

Comments
 (0)