Repository navigation
🐛 fix(help): skip the default suffix when the help already used %(default)s - #405
Merged
gaborbernat merged 4 commits intoNov 18, 2026
Merged
Conversation
…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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An option whose help already shows its default through
%(default)sgot a second(default: ...)appended on the generated page, so the value appeared twice where--helpshows it once. 🐛 Once this merges, the page reads like--helpfor these options: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
defaultin the help as written, which%(default)sitself 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'sArgumentDefaultsHelpFormatterapplies before adding its own default.