You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--disable-error-code=unused-ignore should override enable_error_code = ["unused-ignore"] #20348
Confirmed. It is common knowledge that CLI flags override envvars, and those in turn override configuration file entries (local, then user-level, then global).
This is not specific to --{en,dis}able-error-code, possibly-undefined suffers from the same problem:
$ mypy -c $'if 1:a = 1\nprint(a)' --cache-dir=/dev/null
Success: no issues found in 1 source file
$ cat <<EOF >pyproject.toml[tool.mypy]enable_error_code = ["possibly-undefined"]EOF
$ mypy -c $'if 1:a = 1\nprint(a)' --cache-dir=/dev/null
<string>:2: error: Name "a" may be undefined [possibly-undefined]
Found 1 error in 1 file (checked 1 source file)
$ mypy -c $'if 1:a = 1\nprint(a)' --disable-error-code=possibly-undefined --cache-dir=/dev/null
<string>:2: error: Name "a" may be undefined [possibly-undefined]
Found 1 error in 1 file (checked 1 source file)
Probably all codes that are disabled by default are affected.
The ultimate issue is that enable-error-code has lower priority than disable-error-code, so two strategies clash: --disable-error-code should have higher priority because it is passed as argv, but lower priority because we declare so:
Note: This flag will override disabled error codes from the --disable-error-code flag.
So if both were provided by the same means (both as CLI flags or both as config file entries), this behaviour would be sound, but not when the priority is clear from the source.
Hi! I’m a first-time contributor and I’d like to work on fixing this issue.
Would adjusting the precedence logic in the CLI/config parser and adding tests to ensure that command-line flags correctly override configuration be an okay approach for me to take on?
Activity
wyattscarpenter commentedon Dec 2, 2025
Yep, https://mypy.readthedocs.io/en/stable/config_file.html#config-file-format ("When options conflict, the precedence order...") specifies that command line options should overrule top-level configuration file options. I haven't looked into this further.
sterliakov commentedon Dec 2, 2025
Confirmed. It is common knowledge that CLI flags override envvars, and those in turn override configuration file entries (local, then user-level, then global).
This is not specific to
--{en,dis}able-error-code,possibly-undefinedsuffers from the same problem:Probably all codes that are disabled by default are affected.
The ultimate issue is that
enable-error-codehas lower priority thandisable-error-code, so two strategies clash:--disable-error-codeshould have higher priority because it is passed as argv, but lower priority because we declare so:So if both were provided by the same means (both as CLI flags or both as config file entries), this behaviour would be sound, but not when the priority is clear from the source.
franzengel04 commentedon Dec 2, 2025
Hi! I’m a first-time contributor and I’d like to work on fixing this issue.
Would adjusting the precedence logic in the CLI/config parser and adding tests to ensure that command-line flags correctly override configuration be an okay approach for me to take on?
sterliakov commentedon Dec 2, 2025
@franzengel04 thanks! Yes, that sounds good to me:)
Fix error code precedence to ensure disable overrides enable
Fix error code precedence to ensure disable overrides enable
Fix: Ensure disable overrides enable in Options.apply_changes
Add failing test for per-module error code precedence