Skip to content

Fix TOML boolean false values for store_true options#10903

Open
marwinsteiner wants to merge 2 commits into
pylint-dev:mainfrom
marwinsteiner:fix/toml-boolean-false-config
Open

Fix TOML boolean false values for store_true options#10903
marwinsteiner wants to merge 2 commits into
pylint-dev:mainfrom
marwinsteiner:fix/toml-boolean-false-config

Conversation

@marwinsteiner

Copy link
Copy Markdown

Summary

  • Fix store_true config options (like exit-zero) in TOML files not respecting false values
  • When exit-zero = false is set in TOML, pylint previously treated it the same as exit-zero = true because argparse store_true actions activate from flag presence alone, ignoring the trailing "False" string value
  • Add _fix_store_true_options to _ConfigurationFileParser that introspects the linter's argparse actions to correctly handle boolean values for store_true options only (not yn-type options like --reports)

How it works

After _RawConfParser converts TOML values to ["--flag", "True"/"False"] string pairs, _fix_store_true_options checks each option against the linter's registered _StoreTrueAction actions:

  • True values: emit just the flag (--exit-zero) without the trailing value string
  • False values: omit the flag entirely so argparse uses its default

This distinction is important because other boolean-like options (e.g. --reports) use argparse's yn type and do expect a value argument.

Test plan

  • Added functional test for exit-zero = false in TOML (verifies exit_zero is false)
  • Added functional test for exit-zero = true in TOML (verifies exit_zero is true)
  • All 32 existing functional config loading tests pass without regression

Closes #8460

@github-actions

This comment has been minimized.

@codecov

codecov Bot commented Mar 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.15%. Comparing base (0d77e90) to head (733f62b).
⚠️ Report is 73 commits behind head on main.

Files with missing lines Patch % Lines
pylint/config/config_file_parser.py 86.95% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10903      +/-   ##
==========================================
+ Coverage   96.04%   96.15%   +0.11%     
==========================================
  Files         177      178       +1     
  Lines       19628    19641      +13     
==========================================
+ Hits        18851    18886      +35     
+ Misses        777      755      -22     
Files with missing lines Coverage Δ
pylint/config/config_file_parser.py 96.73% <86.95%> (-3.27%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marwinsteiner

Copy link
Copy Markdown
Author

One CI failure, but it looks like a false positive to me:

************* Module pylint.config.config_file_parser
Notice: Wrong spelling of a word 'linter's' in a comment:
# Build a set of store_true option names from the linter's arg parser
                                                  ^^^^^^^^
Did you mean: ''liner's' or 'liter's''?
Notice: Wrong spelling of a word 'natively' in a docstring:
        TOML files can express boolean values natively (true/false). When these
                                              ^^^^^^^^
Did you mean: ''naively' or 'negatively''?
Notice: Consider using set for membership test

@DanielNoord DanielNoord left a comment

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.

Why not do this in parse_toml_file?

Comment thread pylint/config/config_file_parser.py Outdated
def _fix_store_true_options(self, options: list[str]) -> list[str]:
"""Fix boolean values for store_true argparse actions.

TOML files can express boolean values natively (true/false). When these

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.

You can add it to our spelling dictionary in the root of the repository

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You can add it to our spelling dictionary in the root of the repository

Done. Moved the logic into parse_toml_file and added the spelling words. Thanks for the review!

@marwinsteiner marwinsteiner force-pushed the fix/toml-boolean-false-config branch from be11ef4 to bc4faf4 Compare March 20, 2026 13:12
@github-actions

Copy link
Copy Markdown
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 733f62b

@staticmethod
def parse_toml_file(file_path: Path) -> PylintConfigFileData:
def parse_toml_file(
file_path: Path, store_true_options: set[str] | None = None

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.

Why is this optional?

for opt, values in sections_values.items():
if isinstance(values, dict):
for config, value in values.items():
value = _parse_rich_type_value(value)

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.

There is a lot of duplication. Have you explored if we can do this in _parse_rich_type_value instead?

@Pierre-Sassoulas Pierre-Sassoulas added Waiting on author Indicate that maintainers are waiting for a message of the author Configuration Related to configuration labels May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Configuration Related to configuration Waiting on author Indicate that maintainers are waiting for a message of the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pylint does not respect false values for boolean config options in toml files

3 participants