Repository navigation
mypy section now required in setup.cfg differs from documentation #9940
Description
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:)
- Install mypy locally or via virtualenv
- clone https://github.com/python/mypy
- cd to mypy/test-data/packages/typedpkg
- Run mypy to confirm detect error
mypy -p typedpkg - 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 - 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
Activity
Work around python/mypy#9940
Mypy 0.800 compatibility
mypy 0.800 compatibility
mypy 0.800 compatibility (#668)
Fix/workaround for python/mypy#9940
Work around python/mypy#9940
Work around python/mypy#9940
Work around python/mypy#9940
Work around python/mypy#9940
tests: Add workaround for mypy 0.800 regression
Workaround for python/mypy#9940.
Workaround for python/mypy#9940
fab-spring commentedon Jan 26, 2021
Hey, any timeline on when this will get fixed? Running into similar issues.
Workaround for mypy 0.800 ignoring setup.cfg
Partial cleanups in VM (#667)
Fix/workaround for python/mypy#9940
Partial cleanups in VM (#667)
Unpin mypy version and add empty [mypy] setup.cfg section.
Partial cleanups in VM (#667)
Partial cleanups in VM (#667)
Work around python/mypy#9940
jamescooke commentedon Apr 14, 2021
@electrofelix Thanks for writing this up - I've spent a chunk of time trying to understand why disabling import checking for third party libs wasn't working when configured in
- lots of reading the docs (stable and latest) and searching Issues didn't help.
setup.cfgThe way I spotted the solution was by copypasting the config into
mypy.ini, seeing the warning about"No [mypy] section in config file"and realising that the docs might be out of date regardingsetup.cfg. That got me to search Issues for "setup.cfg" which lead me to this - so thanks again 👍🏻jamescooke commentedon Apr 14, 2021
Would it be a reasonable solution to remove the exception statement from the documentation for now? 22ac062Edit: Have opened #10364 containing that deletion.
Upgrade mypy version
Remove note: setup.cfg *does* need [mypy] section (#10364)
chore: merge upstream to 1.27.3 for ENG-911 (#16)
hauntsaninja commentedon Aug 13, 2023
While I agree that this change should have been advertised better and maybe shouldn't have been made, it's been live for two and a half years, and the docs were updated in #10364