Skip to content

AI junk - #3783

Closed
SirHegel wants to merge 1 commit into
pallets:mainfrom
SirHegel:fix-usage-breaks-options-at-hyphen
Closed

AI junk#3783
SirHegel wants to merge 1 commit into
pallets:mainfrom
SirHegel:fix-usage-breaks-options-at-hyphen

Conversation

@SirHegel

Copy link
Copy Markdown

Fixes #3362.

The problem

wrap_text builds its TextWrapper without setting break_on_hyphens, so it keeps textwrap's default of True. That is the right default for prose — splitting a hyphenated word across lines is normal typesetting — but wrong for a usage line, which is a list of option names.

Reproducing the report on main:

Usage: program --enable-verbose-logging --output-file-path --max-
               retry-count --disable-cache-mode --config-file-
               location --user-auth-token --auto-update-interval
               --force-overwrite-existing --network-timeout-
               seconds --debug-trace-enabled

Three options are split. --max- on its own is not something a reader can copy or type, and it is not obvious from the fragment whether the newline is part of the name.

After

Usage: program --enable-verbose-logging --output-file-path
               --max-retry-count --disable-cache-mode
               --config-file-location --user-auth-token
               --auto-update-interval --force-overwrite-existing
               --network-timeout-seconds --debug-trace-enabled

Byte-identical to the expected output in the issue.

The change

wrap_text gains a break_on_hyphens parameter defaulting to True, so no existing caller changes behaviour. write_usage passes False from both of its branches — the one where arguments sit beside the prefix, and the one where a long prefix pushes them onto their own line.

I kept it scoped to write_usage rather than flipping the default globally, since prose help text is a different case and that would be a wider behavioural change than the issue calls for.

Tests

Two regression tests: one reproducing the report exactly and asserting the full expected output, one covering the long-prefix branch. The first fails on main.

Note the second test uses width=40 deliberately — at narrower widths the option is wider than the line and break_long_words splits it, which is a separate mechanism and not what this fixes.

Full suite: 1993 passed, 24 skipped, 1 xfailed.

Fixes pallets#3362.

wrap_text builds a TextWrapper without setting break_on_hyphens, so it keeps
textwrap's default of True. That is right for prose, where splitting a
hyphenated word across lines is normal typesetting, but wrong for a usage
line, which is a list of option names. An option split at a hyphen leaves a
fragment the reader cannot copy or type:

    Usage: program --enable-verbose-logging --output-file-path --max-
                   retry-count --disable-cache-mode --config-file-

Adds break_on_hyphens to wrap_text, defaulting to the current behaviour so no
existing caller changes, and passes False from both branches of write_usage.

Adds a regression test reproducing the report exactly, and one covering the
long-prefix branch where the arguments move to their own line.
@davidism

Copy link
Copy Markdown
Member

@davidism davidism closed this Aug 20, 2026
@davidism davidism added the rejected AI Contribution rejected because of its untrustworthy AI origin label Aug 20, 2026
@SirHegel

Copy link
Copy Markdown
Author

Let me give you the calculation, and then manually check the solution.

@davidism davidism changed the title Do not break option names at hyphens in the usage line AI junk Aug 20, 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

2 participants