Skip to content

Fix HelpFormatter.write_usage with empty args#3402

Open
Im-Siyoun wants to merge 1 commit intopallets:mainfrom
Im-Siyoun:fix-helpformatter-empty-args
Open

Fix HelpFormatter.write_usage with empty args#3402
Im-Siyoun wants to merge 1 commit intopallets:mainfrom
Im-Siyoun:fix-helpformatter-empty-args

Conversation

@Im-Siyoun
Copy link
Copy Markdown

Fixes #3360.

This fixes HelpFormatter.write_usage() when it is called without args.

Previously, write_usage("Program") passed an empty string to wrap_text() while using the usage prefix as initial_indent. Since there was no text to wrap, wrap_text() returned an empty string and only a blank line was written.

This change preserves the usage prefix for the empty-args case, so write_usage("Program") now writes:

"Usage: Program \n"

Tests were added to cover this behavior.

Tests run:

pytest tests/test_formatting.py -q
pytest

@Im-Siyoun
Copy link
Copy Markdown
Author

I noticed after opening this PR that #3382 and #3383 previously attempted to address the same issue and were closed.

This PR takes a slightly different approach by preserving the existing trailing-space behavior from the usage prefix. In the empty-args case, write_usage("Program") writes "Usage: Program \n" instead of only "\n".

If this behavior is not desired, or if there is a preferred direction for this issue, I’m happy to adjust the PR or close it.

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.

Empty output from HelpFormatter.write_usage for a program without arguments

1 participant