Skip to content

Conversation

sigvef
Copy link

@sigvef sigvef commented Aug 23, 2025

Mypy has options for enabling or disabling specific error codes. These
work fine, except that it is not possible to enable or disable error
codes from plugins, only mypy's original error codes.

The crux of the issue is that mypy validates and rejects unknown error
codes passed in the options before it loads plugins and learns about the
any error codes that might get registered.

There are many ways to solve this. This commit tries to find a pragmatic
solution where the relevant options parsing is deferred until after
plugin loading. Error code validation in the config parser, where
plugins are not loaded yet, is also skipped entirely, since the error
code options are re-validated later anyway. This means that this commit
introduces a small observable change in behavior when running with
invalid error codes specified, as shown in the test
test_config_file_error_codes_invalid.

This fixes #12987.

@sigvef sigvef force-pushed the plugin-error-codes branch 3 times, most recently from 17b8cac to 3b08bd3 Compare August 23, 2025 23:00

This comment has been minimized.

@sigvef sigvef force-pushed the plugin-error-codes branch 2 times, most recently from dacdf4b to c056317 Compare August 24, 2025 06:43
Mypy has options for enabling or disabling specific error codes. These
work fine, except that it is not possible to enable or disable error
codes from plugins, only mypy's original error codes.

The crux of the issue is that mypy validates and rejects unknown error
codes passed in the options before it loads plugins and learns about the
any error codes that might get registered.

There are many ways to solve this. This commit tries to find a pragmatic
solution where the relevant options parsing is deferred until after
plugin loading. Error code validation in the config parser, where
plugins are not loaded yet, is also skipped entirely, since the error
code options are re-validated later anyway. This means that this commit
introduces a small observable change in behavior when running with
invalid error codes specified, as shown in the test
test_config_file_error_codes_invalid.

This fixes python#12987.
@sigvef sigvef force-pushed the plugin-error-codes branch from c056317 to 3ebd792 Compare August 24, 2025 06:50
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sigvef sigvef marked this pull request as ready for review August 24, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ErrorCodes defined in mypy plugins seemingly cannot be ignored by --disable-error-code
1 participant