Skip to content

Commit 7bae510

Browse files
allow --enable-all-error-codes to be countermanded
1 parent 8066787 commit 7bae510

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

docs/source/command_line.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ of the above sections.
808808
See :ref:`error-codes` and :ref:`error-codes-optional`
809809
for more information.
810810

811-
This flag will override disabled error codes from the
812-
:option:`--disable-error-code <mypy --disable-error-code>` flag.
811+
(Unlike the other flag for error code enablement, these can be countermanded
812+
with :option:`--disable-error-code`.)
813813

814814
Note that future releases of mypy will likely introduce more error codes,
815815
so the effective result of using this flag will change from release to

docs/source/config_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ section of the command line docs.
768768

769769
Enables all mypy error codes.
770770

771-
Note: This option will override disabled error codes from the disable_error_code option.
771+
Note: This option will be overridden by disabled error codes from the disable_error_code option.
772772

773773
.. confval:: extra_checks
774774

docs/source/error_codes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ to enable or disable specific error codes that don't have a dedicated
5151
command-line flag or config file setting.
5252

5353
:option:`--enable-all-error-codes <mypy --enable-all-error-codes>` enables
54-
all optional error codes. (Remember that enabling takes priority over
55-
disabling, so other --disable-error-code flags will not countermand this.)
54+
all optional error codes. (Unlike the other flag for error code enablement,
55+
these can be countermanded with :option:`--disable-error-code <mypy --disable-error-code>`.)
5656

5757
Per-module enabling/disabling error codes
5858
-----------------------------------------

mypy/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,10 @@ def add_invertible_flag(
954954
help="Enable a specific error code",
955955
)
956956
strictness_group.add_argument(
957-
"--enable-all-error-codes", action="store_true", help="Enable all error codes"
957+
"--enable-all-error-codes",
958+
action="store_true",
959+
help="Enable all error codes. Unlike the other flag for error code enablement,"
960+
+ " these can be countermanded by --disable-error-code",
958961
)
959962

960963
error_group = parser.add_argument_group(

mypy/options.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,18 @@ def process_error_codes(self, *, error_callback: Callable[[str], Any]) -> None:
452452
error_callback(f"Invalid error code(s): {', '.join(sorted(invalid_codes))}")
453453

454454
self.disabled_error_codes |= {error_codes[code] for code in disabled_codes}
455-
if self.enable_all_error_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}
455+
self.enabled_error_codes |= {error_codes[code] for code in enabled_codes}
459456

460457
# Enabling an error code always overrides disabling
461458
self.disabled_error_codes -= self.enabled_error_codes
462459

460+
# enable_all_error_codes codes can be countermanded by disabled_error_codes, which
461+
# can in turn be countermanded by enabled_error_codes. But we've just computed the
462+
# latter countermanding, so we can use the set of disabled_error_codes that weren't
463+
# countermanded to figure out what to really turn off.
464+
if self.enable_all_error_codes:
465+
self.enabled_error_codes = set(error_codes.values()) - self.disabled_error_codes
466+
463467
def process_incomplete_features(
464468
self, *, error_callback: Callable[[str], Any], warning_callback: Callable[[str], Any]
465469
) -> None:

0 commit comments

Comments
 (0)