formatting: don't break wrapped text at hyphens#3544
Closed
sapirbaruch wants to merge 1 commit into
Closed
Conversation
CLI option names and other hyphenated tokens (e.g. --enable-verbose-logging) are split at the hyphen when they fall exactly at the text-wrap boundary. textwrap.TextWrapper.break_on_hyphens defaults to True, which is designed for prose but is wrong for a CLI help formatter where option names, paths, and compound identifiers must stay intact. Pass break_on_hyphens=False to the TextWrapper so that wrap_text, and by extension HelpFormatter.write_usage / write_text, only ever break at whitespace. Fixes pallets#3362
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.
Fixes #3362.
textwrap.TextWrapperdefaults tobreak_on_hyphens=True, which breaks compound words at hyphens when they fall at the wrap boundary. That default is designed for English prose, but a CLI help formatter is not prose — option names like--enable-verbose-logging, paths, and other hyphenated identifiers should never be split at a hyphen.Before this change,
write_usagecould produce:After:
The fix is a single-line change: pass
break_on_hyphens=Falseto theTextWrapperconstructor insidewrap_text. All existing tests continue to pass (none depended on hyphen-breaking behaviour), and a new test captures the regression.