Skip to content

Do not break usage line arguments at a hyphen - #3782

Open
fahadhewad wants to merge 1 commit into
pallets:mainfrom
fahadhewad:fix-usage-hyphen-wrap
Open

Do not break usage line arguments at a hyphen#3782
fahadhewad wants to merge 1 commit into
pallets:mainfrom
fahadhewad:fix-usage-hyphen-wrap

Conversation

@fahadhewad

Copy link
Copy Markdown

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.

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.
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.

HelpFormatter.write_usage breaks options at a hyphen

1 participant