python / python/mypy

local / in-folder setup.cfg without mypy section shadows any additional user config files

Open
#9,113 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-configuration
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

As the config file read order defined by the order of the lists at https://github.com/python/mypy/blob/master/mypy/defaults.py#L15
is

CONFIG_FILES = CONFIG_FILE + SHARED_CONFIG_FILES + USER_CONFIG_FILES  # type: Final

a shared config file (which may exist for several other purposes) shadows any user config files even in the case when
the shared config file contains no mypy section.

Steps to reproduce:

  • Create an empty setup.cfg in the current directory, and also have one of the USER_CONFIG_FILE versions of a mypy config file.
  • Run mypy
  • Notice that only the setup.cfg file was read, even though it had no mypy section.
    `

Proposal

The logic which checks for a mypy section in the parser object (https://github.com/python/mypy/blob/master/mypy/config_parser.py#L127) should be used to check whether the parser.read call actually loaded anything meaningful from the config file. If no mypy section was loaded, then the loop over the config_files should continue instead of breaking.

This should at least be the case for any shared config files which may exist for entirely other reasons.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CONFIG_FILES ordering in mypy/defaults.py and the parser section check in mypy/config_parser.py. Reproduce the issue using an empty setup.cfg and a user config file, then verify that configuration loading continues when the shared file has no mypy section and that the user settings take effect.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.