Skip to content

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

Closed

Description

@dougthor42

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

Activity

  1. 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
  2. ahmed-moubtahij commented on Jun 30, 2022

    @ahmed-moubtahij

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

    [mypy-file_name.class_name.*]
    disable_error_code = attr-defined
    
  3. ManuelZ commented on Jul 15, 2022

    @ManuelZ

    When I did the same as @Ayenem, MyPy told me:
    Per-module sections should only specify per-module flags (disable_error_code)

  4. msn commented on Dec 2, 2022

    @msn

    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.

  5. hauntsaninja commented on Dec 2, 2022

    @hauntsaninja
    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

  6. justinchuby commented on Mar 10, 2023

    @justinchuby

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-configurationConfiguration files and flags

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions