Do not break usage line arguments at a hyphen - #3782
Open
fahadhewad wants to merge 1 commit into
Open
Conversation
HelpFormatter.write_usage wrapped its arguments with textwrap's break_on_hyphens behaviour enabled, so an option name or metavar that reached the wrap width was split across two lines at an internal hyphen, for example --max- on one line and retry-count on the next. Wrap the usage arguments with hyphen breaking disabled so a hyphenated token moves to the next line whole, and add a break_on_hyphens argument to wrap_text so other callers can choose the behaviour they want. 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.
The usage line wrapped its arguments with textwrap's break_on_hyphens behaviour enabled, so an option name or metavar that reached the wrap width was split across two lines at an internal hyphen, for example --max- on one line and retry-count on the next.
HelpFormatter.write_usage now wraps the arguments with hyphen breaking disabled, so a hyphenated token moves to the next line whole. wrap_text gains a break_on_hyphens argument that defaults to True, so help text wraps exactly as before and other callers can pick the behaviour they want.
fixes #3362
Three tests are added in tests/test_formatting.py, one for wrap_text with and without break_on_hyphens, and one for each of the two wrapping branches of write_usage. All three fail without the change. CHANGES.md has an entry under 8.5.0, and versionchanged notes are added to wrap_text and write_usage. The full test suite and ruff check both pass.