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
Inline config 'disable-error-code = attr-defined' does not disable errors #11462
$ mypy example.py
Success: no issues found in 1 source file
Actual Behavior
mypy complains about line 3:
$ mypy example.py
example.py:3: error: "Type[Foo]" has no attribute "a"
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: 0.910
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): None
Python version used: 3.6.8, 3.8.1
Operating system and version: Ubuntu 18.04.3 "bionic" running on WSL1 on Windows 10 Pro 20H2
$ pip list
Package Version
----------------- --------
mypy 0.910
mypy-extensions 0.4.3
pip 21.3.1
setuptools 58.5.2
toml 0.10.2
typed-ast 1.4.3 # for Python 3.6
typing-extensions 3.10.0.2
wheel 0.37.0
Other Notes
Running with --disable-error-code attr-defined from the CLI works:
$ mypy example.py --disable-error-code attr-defined
Success: no issues found in 1 source file
Creating a mypy.ini file in the same directory as example.py and populating it with:
[mypy]
disable_error_code = attr-defined
causes the expected behavior (no mypy errors), so it's appears to only be an issue with the inline configuration. Sadly my use case requires me to only ignore these errors on a single file, so using the global mypy.ini config file is not an option.
Deleting the .mypy-cache directory does not resolve the issue.
Note: If you run other tests (like 1, 2 above), then deleting .mypy-cache is required to get back to a state where the inline-config fails to apply
changed the title [-]Module-level 'disable-error-code = attr-defined' does not disable errors[/-][+]Inline config 'disable-error-code = attr-defined' does not disable errors[/+]on Nov 4, 2021
Also ran into this and ended up having to work around by putting # type: ignore on all the relevant lines where dynamic attributes were involved in lieu of a better solution.
Activity
[-]Module-level 'disable-error-code = attr-defined' does not disable errors[/-][+]Inline config 'disable-error-code = attr-defined' does not disable errors[/+]ahmed-moubtahij commentedon Jun 30, 2022
Same issue. Going through the config file didn't work either:
ManuelZ commentedon Jul 15, 2022
When I did the same as @Ayenem, MyPy told me:
Per-module sections should only specify per-module flags (disable_error_code)msn commentedon Dec 2, 2022
Also ran into this and ended up having to work around by putting # type: ignore on all the relevant lines where dynamic attributes were involved in lieu of a better solution.
hauntsaninja commentedon Dec 2, 2022
# mypy: disable-error-code="attr-defined"Per-module error code handling was added in mypy 0.981 or something. https://mypy.readthedocs.io/en/stable/error_codes.html#per-module-enabling-disabling-error-codes
justinchuby commentedon Mar 10, 2023
For multiple error codes:
# mypy: disable-error-code="misc,arg-type,type-arg,valid-type,assignment,return-value"