AI junk - #3794
Closed
yfwmaniish wants to merge 1 commit into
Closed
Conversation
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
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. |
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.
What
HelpFormatter.write_usagewraps the "Usage: ..." line viawrap_text, which builds a stdlibtextwrap.TextWrapperwithout overridingbreak_on_hyphens(defaultTrue).textwraptreats each internal hyphen in a word as a valid break point, so a long option name like--max-retry-countcould get split mid-token across two lines ("--max-\nretry-count"), making it unrecognizable as a single flag.Fix
Added a
break_on_hyphensparameter towrap_text(defaultTrue, 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 passbreak_on_hyphens=Falsefromwrite_usage's twowrap_textcall 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_namesuses the exact reproduction and width fromHelpFormatter.write_usagebreaks 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_proseconfirmswrite_text/write_dl's hyphen-breaking for prose is unaffected by the new parameter's default.ruff check/ruff format --diffandmypyare clean with the fix applied.Notes for review
CHANGES.mdentry under a new## Unreleasedsection, 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... versionadded:: 8.6.0docstring directive is my best guess at the next release version; please adjust if this lands as a different version number.