Skip to content

Fix output config option in mypy.ini#21416

Open
mitre88 wants to merge 1 commit intopython:masterfrom
mitre88:fix/output-config-ini
Open

Fix output config option in mypy.ini#21416
mitre88 wants to merge 1 commit intopython:masterfrom
mitre88:fix/output-config-ini

Conversation

@mitre88
Copy link
Copy Markdown

@mitre88 mitre88 commented May 5, 2026

The config parser was skipping options whose default value is None (e.g. 'output'), even when the attribute exists on the Options class.

This was due to the condition 'dv is None' being used to skip unknown options, but some valid options intentionally have None defaults.

The fix changes the condition to skip only options that don't exist on the template Options object (using hasattr), allowing options like 'output' to be set in config files.

Fixes #21376

The config parser was skipping options whose default value is None
(e.g. 'output'), even when the attribute exists on the Options class.
This was due to the condition 'dv is None' being used to skip unknown
options, but some valid options intentionally have None defaults.

The fix changes the condition to skip only options that don't exist
on the template Options object (using hasattr), allowing options like
'output' to be set in config files.

Fixes python#21376
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@A5rocks
Copy link
Copy Markdown
Collaborator

A5rocks commented May 7, 2026

Please add a test. I notice the diff is quite different than #21398 so I'm not sure what's going on here :/

Comment thread mypy/config_parser.py
else:
dv = getattr(template, options_key, None)
if dv is None:
if dv is None and not hasattr(template, options_key):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if dv is None and not hasattr(template, options_key):
if not hasattr(template, options_key):

I feel like this is simpler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot set output in mypy.ini

2 participants