Skip to content

AI junk - #3794

Closed
yfwmaniish wants to merge 1 commit into
pallets:mainfrom
yfwmaniish:fix/usage-hyphenated-option-wrap
Closed

AI junk#3794
yfwmaniish wants to merge 1 commit into
pallets:mainfrom
yfwmaniish:fix/usage-hyphenated-option-wrap

Conversation

@yfwmaniish

Copy link
Copy Markdown

Fixes #3362.

What

HelpFormatter.write_usage wraps the "Usage: ..." line via wrap_text, which builds a stdlib textwrap.TextWrapper without overriding break_on_hyphens (default True). textwrap treats each internal hyphen in a word as a valid break point, so a long option name like --max-retry-count could get split mid-token across two lines ("--max-\nretry-count"), making it unrecognizable as a single flag.

Fix

Added a break_on_hyphens parameter to wrap_text (default True, so every other current caller -- write_text's prose help descriptions, write_dl's option-description column -- keeps wrapping hyphenated compound words exactly as before) and pass break_on_hyphens=False from write_usage's two wrap_text call sites, since usage-line tokens are option/argument names, not prose that should hyphenate like normal English text.

Testing

  • test_write_usage_does_not_break_hyphenated_option_names uses the exact reproduction and width from HelpFormatter.write_usage breaks options at a hyphen #3362 -- asserts the precise expected output from the issue, line for line.
  • test_wrap_text_break_on_hyphens_default_still_breaks_prose confirms write_text/write_dl's hyphen-breaking for prose is unaffected by the new parameter's default.
  • Verified as a negative control: both new tests fail on unfixed source with the exact reported symptom (mid-hyphen break / missing parameter -- see commit message for the exact diff), and the whole test suite (1915 tests) plus ruff check/ruff format --diff and mypy are clean with the fix applied.

Notes for review

  • Added a CHANGES.md entry under a new ## Unreleased section, but left the {pr} role off since the PR number wasn't assigned yet -- happy to fill it in, or you're welcome to during merge.
  • The .. versionadded:: 8.6.0 docstring directive is my best guess at the next release version; please adjust if this lands as a different version number.

HelpFormatter.write_usage wraps the "Usage: ..." line via wrap_text,
which builds a stdlib textwrap.TextWrapper without overriding
break_on_hyphens (default True). textwrap treats each internal hyphen
in a word as a valid break point, so a long option name like
--max-retry-count could get split mid-token across two lines
("--max-\nretry-count"), making it unrecognizable as a single flag.

Added a break_on_hyphens parameter to wrap_text (default True, so
every other current caller -- write_text's prose help descriptions,
write_dl's option-description column -- keeps wrapping hyphenated
compound words exactly as before) and pass break_on_hyphens=False from
write_usage's two wrap_text call sites, since usage-line tokens are
option/argument names, not prose.

Testing:
- Added test_write_usage_does_not_break_hyphenated_option_names,
  using the exact reproduction and width from pallets#3362 -- asserts the
  precise expected output from the issue, line for line.
- Added test_wrap_text_break_on_hyphens_default_still_breaks_prose,
  confirming write_text/write_dl's hyphen-breaking for prose is
  unaffected by the new parameter's default.
- Verified as a negative control: both new tests fail on unfixed
  source with the exact reported symptom (mid-hyphen break / missing
  parameter), and the whole test suite (1915 tests) plus ruff
  check/format and mypy are clean with the fix applied.

CHANGES.md entry added under a new Unreleased section; left the {pr}
role off since the PR number isn't assigned yet, and the
.. versionadded:: 8.6.0 docstring directive is a best guess at the
next release -- happy to adjust either if this lands differently.

Fixes pallets#3362
@yfwmaniish

Copy link
Copy Markdown
Author

Withdrawing this -- I found Pallets' AI contribution policy (https://palletsprojects.com/contributing/llm-ai) after opening this, which I should have checked before submitting. Closing it myself rather than leaving it for a maintainer to catch. Apologies for the noise.

@davidism davidism added the rejected AI Contribution rejected because of its untrustworthy AI origin label Aug 25, 2026
@davidism davidism changed the title fix: don't break hyphenated option names when wrapping the usage line AI junk Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected AI Contribution rejected because of its untrustworthy AI origin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HelpFormatter.write_usage breaks options at a hyphen

3 participants