Same module cannot appear in multiple disable_error_code overrides
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
In my pyproject.toml file I have created some overrides to disable specific checks for specific files.
This is because I am adding type checking to an existing legacy repository, I don't have the time to update all the existing legacy code, but don't want to disable the checks entirely - when we write new code I'd like it to be properly type-checked.
When I include the same module in two [[tool.mypy.overrides]] I get a conflict error...
To Reproduce
Add the same module into multiple overrides blocks:
[[tool.mypy.overrides]]
disable_error_code = [
"attr-defined",
]
module=[
"foo.bar.baz",
"my.other.module",
]
[[tool.mypy.overrides]]
disable_error_code = [
"union-attr",
]
module=[
"foo.bar.baz",
]
I get the error:
pyproject.toml: toml config file contains [[tool.mypy.overrides]] sections with conflicting values. Module 'foo.bar.baz' has two different values for 'disable_error_code'
Expected Behavior
It should permit a module being in multiple overrides blocks.
The reason this is advantageous is because a given check (e.g. "union-attr") may need a different set of module exceptions to another check.
Actual Behavior
The error prevents this setup from functioning.
Your Environment
- Mypy version used: 1.5.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files):
[tool.mypy]
python_version = "3.9"
warn_unused_ignores = true
no_implicit_optional = false
no_strict_optional = true
allow_redefinition = true
disable_error_code = [
"annotation-unchecked", # Suppress warning notes
"no-redef", # this one is just annoying
]
exclude = [
<Some paths>
]
# This ignores mypy for libraries that do not themselves use type annotations.
[[tool.mypy.overrides]]
module = [
<Some imports>
]
ignore_missing_imports = true
# Selective disable of override checks
[[tool.mypy.overrides]]
disable_error_code = [
"override",
]
module=[
<Some modules>
]
# Selective disable of union-attr checks
[[tool.mypy.overrides]]
disable_error_code = [
"union-attr",
]
module=[
<Some modules>
]
# Selective disable of assignment checks
[[tool.mypy.overrides]]
disable_error_code = [
"assignment",
]
module=[
<Some modules>
]
# Selective disable of call-overload checks
[[tool.mypy.overrides]]
disable_error_code = [
"call-overload",
]
module=[
<Some modules>
]
# Selective disable of arg-type checks
[[tool.mypy.overrides]]
disable_error_code = [
"arg-type",
]
module=[
<Some modules>
]
# Selective disable of misc checks
[[tool.mypy.overrides]]
disable_error_code = [
"misc",
]
module=[
<Some modules>
]
# Selective disable of attr-defined checks
[[tool.mypy.overrides]]
disable_error_code = [
"attr-defined",
]
module=[
<Some modules>
]
- Python version used: 3.9.17
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the conflict with the provided pyproject.toml [[tool.mypy.overrides]] configuration and the mypy 1.5.0 example. Trace how multiple override blocks are validated and merged, then verify that the same module can specify separate disable_error_code values without a conflict. Done means the example configuration is accepted while existing conflicting-value validation still behaves correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100