Skip to content

🐛 fix(help): skip the default suffix when the help already used %(default)s - #405

Merged
gaborbernat merged 4 commits into
tox-dev:mainfrom
abhishekcpp007:fix/default-suffix-after-expansion
Nov 18, 2026
Merged

gaborbernat merged 4 commits into
tox-dev:mainfrom
abhishekcpp007:fix/default-suffix-after-expansion

Conversation

@abhishekcpp007

@abhishekcpp007 abhishekcpp007 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

An option whose help already shows its default through %(default)s got a second (default: ...) appended on the generated page, so the value appeared twice where --help shows it once. 🐛 Once this merges, the page reads like --help for these options:

parser.add_argument("--format", default="text", help="output format [%(default)s]")
* **"--format"** "FORMAT" - output format [text] (default: "text")    # before
* **"--format"** "FORMAT" - output format [text]                      # after

The regression came with #355, which expands format specifiers in help text. The extension appends the default only when the help does not already mention one. Before #355 it looked for the word default in the help as written, which %(default)s itself matched; since #355 it looks in the expanded text, where the placeholder has already turned into the value. The suffix is now skipped when either the expanded text mentions a default or the help as written contains a %(default) placeholder in any conversion, the same test argparse's ArgumentDefaultsHelpFormatter applies before adding its own default.

abhishekcpp007 and others added 2 commits November 11, 2026 22:54
…ault)s

#355 started expanding %(default)s before deciding whether to append (default: ...), but the regex that looks for the word default ran on the expanded text. Once the placeholder became its value the word was usually gone, so the option got the default twice. argparse makes this call on the raw help, so check it there too.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 17, 2026
Merging main brought ruff's too-many-boolean-expressions check (6 > 5) onto
the default-suffix condition. Searching the help as written with the
existing default regex covers the %(default)s placeholder in the same
term as the expanded-text search.
@gaborbernat
gaborbernat merged commit 7657e54 into tox-dev:main Nov 18, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants