Skip to content

Commit 5969001

Browse files
add all error code
1 parent f336726 commit 5969001

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

docs/source/error_code_list.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ with default options. See :ref:`error-codes` for general documentation
88
about error codes. :ref:`error-codes-optional` documents additional
99
error codes that you can enable.
1010

11+
.. _code-all:
12+
13+
Enable all error codes
14+
----------------------
15+
16+
While not really an error code mypy will ever display, providing ``all``
17+
as an error code to be enabled (via the command-line) enables
18+
all optional error codes. (Remember that enabling takes priority over
19+
disabling, so other --disable-error-code flags will not countermand this.)
20+
1121
.. _code-attr-defined:
1222

1323
Check that attribute exists [attr-defined]

docs/source/error_codes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ and :option:`--disable-error-code <mypy --disable-error-code>`
5050
to enable or disable specific error codes that don't have a dedicated
5151
command-line flag or config file setting.
5252

53+
While not really an error code mypy will ever display, providing ``all``
54+
as an error code to be enabled (via the command-line) enables
55+
all optional error codes. (Remember that enabling takes priority over
56+
disabling, so other --disable-error-code flags will not countermand this.)
57+
5358
Per-module enabling/disabling error codes
5459
-----------------------------------------
5560

@@ -99,6 +104,7 @@ So one can e.g. enable some code globally, disable it for all tests in
99104
the corresponding config section, and then re-enable it with an inline
100105
comment in some specific test.
101106

107+
102108
Subcodes of error codes
103109
-----------------------
104110

mypy/errorcodes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def __eq__(self, other: object) -> bool:
4545
def __hash__(self) -> int:
4646
return hash((self.code,))
4747

48-
4948
ATTR_DEFINED: Final = ErrorCode("attr-defined", "Check that attribute exists", "General")
5049
NAME_DEFINED: Final = ErrorCode("name-defined", "Check that name is defined", "General")
5150
CALL_ARG: Final[ErrorCode] = ErrorCode(
@@ -156,6 +155,12 @@ def __hash__(self) -> int:
156155
"await-not-async", 'Warn about "await" outside coroutine ("async def")', "General"
157156
)
158157
# These error codes aren't enabled by default.
158+
ALL: Final[ErrorCode] = ErrorCode(
159+
"all",
160+
"Enable all error codes for mypy (although not necessarily for plugins), including the optional ones that are off by default",
161+
"General",
162+
default_enabled=False,
163+
)
159164
NO_UNTYPED_DEF: Final[ErrorCode] = ErrorCode(
160165
"no-untyped-def", "Check that every function has an annotation", "General"
161166
)

mypy/options.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,11 @@ def process_error_codes(self, *, error_callback: Callable[[str], Any]) -> None:
451451
error_callback(f"Invalid error code(s): {', '.join(sorted(invalid_codes))}")
452452

453453
self.disabled_error_codes |= {error_codes[code] for code in disabled_codes}
454-
self.enabled_error_codes |= {error_codes[code] for code in enabled_codes}
454+
#TODO: does this also apply for configuration files as well, or just the command line?
455+
if "all" in enabled_codes:
456+
self.enabled_error_codes = set(error_codes.values())
457+
else:
458+
self.enabled_error_codes |= {error_codes[code] for code in enabled_codes}
455459

456460
# Enabling an error code always overrides disabling
457461
self.disabled_error_codes -= self.enabled_error_codes

0 commit comments

Comments
 (0)