Skip to content

fix: read exclude and non-cap from configuration files as lists - #411

Merged
weibullguy merged 1 commit into
PyCQA:masterfrom
TohruSu:fix-config-file-list-options
Nov 3, 2026
Merged

weibullguy merged 1 commit into
PyCQA:masterfrom
TohruSu:fix-config-file-list-options

Conversation

@TohruSu

@TohruSu TohruSu commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

When exclude or non-cap comes from setup.cfg or tox.ini, configparser returns a string, and that string becomes the argparse default as-is. find_py_files() then loops over it character by character, so almost every path matches. For example, with

[docformatter]
exclude = build

docformatter --check --recursive . checks nothing and exits 0. The same happens with the bracketed form used in the existing setup.cfg tests (exclude = ["src/", "tests/"]) and with a string value in pyproject.toml. non-cap has the same problem; there it turns into a substring check.

I couldn't find an issue for this. #276 touched the same code but was closed without merging.

Changes

Configurater._do_get_list_option() now builds the defaults for --exclude and --non-cap:

  • TOML arrays are passed through.
  • A bracketed list like ["build", "dist"] is parsed with ast.literal_eval.
  • Anything else is split on whitespace, so build, build dist and one name per line all work, the same as nargs="*" on the command line.

flargs keeps the raw values, so the existing tests are unaffected.

Tests

New TestListOptionsFromConfigFile in tests/test_configuration_functions.py, 11 tests:

  • setup.cfg / tox.ini with bracketed, single, space-separated and multi-line values
  • pyproject.toml with a string and an array
  • an end-to-end --check --recursive run with exclude = build

On current master 10 of them fail (the TOML array case already worked); with the fix all 11 pass.

Testing

Windows 10, Python 3.11:

  • Full suite: 755 passed before, 766 after. The same 1 failure and 36 errors show up with and without this change: the errors come from fixtures that write to /tmp, and the failure is the Windows-only preserve_line_ending case.
  • Because of the /tmp fixtures, test_exclude_from_setup_cfg and test_non_cap_from_setup_cfg didn't run here. I checked those configs by hand and they now produce lists.
  • black, isort, ruff, pydocstyle, mypy, pylint and docformatter are clean on configuration.py.
  • I haven't run it on Linux, so CI will be the first run there.

@weibullguy
weibullguy merged commit 556b48f into PyCQA:master Nov 3, 2026
7 checks passed
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.

2 participants