Skip to content

mypy section now required in setup.cfg differs from documentation #9940

Closed
@electrofelix

Description

@electrofelix

Bug Report

Existing setup.cfg with a section that looks like [mypy-myapp.mymodule] containing an ignore_errors = True setting is no longer picked up as expected by mypy 0.800.

The behaviour documented at https://mypy.readthedocs.io/en/stable/config_file.html#config-file-format indicates that a section [mypy] is optional for setup.cfg files. However with a recent change it is now required.

PR #9114 introduces a change to skip setup.cfg to avoid another issue where use of setup.cfg was shadowing any additional user configs covered in #9113.

To maintain compatibility with existing configs potentially the check should be:

    if (config_file in defaults.SHARED_CONFIG_FILES and
            not any(section.startswith("mypy-") for section in parser.sections()))
        ....

It may be preferred to deprecate the existing documented behaviour, and be able to rely on needing there always to be a mypy section instead of treating setup.cfg as special. In the short term however it might be better to add a deprecation notice when this is detected and retain compatibility with existing setup.cfg that do not include an [mypy] section for now.

To Reproduce

(Write your steps here:)

  1. Install mypy locally or via virtualenv
  2. clone https://github.com/python/mypy
  3. cd to mypy/test-data/packages/typedpkg
  4. Run mypy to confirm detect error
    mypy -p typedpkg
    
  5. Create a setup.cfg that should ignore these errors and execute mypy:
    cat <<EOF > setup.cfg
    [mypy-typedpkg.sample]
    ignore_errors = True
    EOF
    mypy -p typedpkg
    
  6. Replace with a setup.cfg that contains an empty [mypy]
    cat <<EOF > setup.cfg
    [mypy]
    
    [mypy-typedpkg.sample]
    ignore_errors = True
    EOF
    mypy -p typedpkg
    

Expected Behavior

Error should be produce for the first execution of mypy, and success reported for the latter two

Output from step 4:

typedpkg/sample.py:7: error: Incompatible return value type (got "List[str]", expected "Tuple[str, ...]")
Found 1 error in 1 file (checked 5 source files)

Output from step 5:

Success: no issues found in 5 source files

Output from step 6:

Success: no issues found in 5 source files

Actual Behavior

Output from step 4:

typedpkg/sample.py:7: error: Incompatible return value type (got "List[str]", expected "Tuple[str, ...]")
Found 1 error in 1 file (checked 5 source files)

Output from step 5:

typedpkg/sample.py:7: error: Incompatible return value type (got "List[str]", expected "Tuple[str, ...]")
Found 1 error in 1 file (checked 5 source files)

Output from step 6:

Success: no issues found in 5 source files

Your Environment

  • Mypy version used: 0.800
  • Python version used: 3.9.1
  • Operating system and version: Ubuntu 20.04

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