Skip to content

Inline config 'disable-error-code = attr-defined' does not disable errors #11462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dougthor42 opened this issue Nov 4, 2021 · 5 comments
Closed
Labels
bug mypy got something wrong topic-configuration Configuration files and flags

Comments

@dougthor42
Copy link

Bug Report

Setting # mypy: disable-error-code = attr-defined within a module does not disable those errors.

To Reproduce

  1. Create the example file:
    $ echo "# mypy: disable-error-code = attr-defined
    > class Foo: pass
    > Foo.a" > example.py
    # mypy: disable-error-code = attr=defined
    class Foo: pass
    Foo.a
  2. Run mypy example.py

Expected Behavior

mypy should not complain about any errors:

$ 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

  1. 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
  2. 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.
  3. 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
@dougthor42 dougthor42 added the bug mypy got something wrong label Nov 4, 2021
@dougthor42 dougthor42 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 Nov 4, 2021
@JelleZijlstra JelleZijlstra added the topic-configuration Configuration files and flags label Mar 21, 2022
@ahmed-moubtahij
Copy link

ahmed-moubtahij commented Jun 30, 2022

Same issue. Going through the config file didn't work either:

[mypy-file_name.class_name.*]
disable_error_code = attr-defined

@ManuelZ
Copy link

ManuelZ commented 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
Copy link

msn commented 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
Copy link
Collaborator

# 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
Copy link

For multiple error codes:

# mypy: disable-error-code="misc,arg-type,type-arg,valid-type,assignment,return-value"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-configuration Configuration files and flags
Projects
None yet
Development

No branches or pull requests

7 participants