Skip to content

Fix HelpFormatter.write_usage dropping prefix when args is empty#3415

Closed
bibekmhj wants to merge 1 commit intopallets:mainfrom
bibekmhj:fix/3360-write-usage-empty-args
Closed

Fix HelpFormatter.write_usage dropping prefix when args is empty#3415
bibekmhj wants to merge 1 commit intopallets:mainfrom
bibekmhj:fix/3360-write-usage-empty-args

Conversation

@bibekmhj
Copy link
Copy Markdown

Fixes #3360.

Tracked this down — when args="" the function calls wrap_text("", ..., initial_indent=usage_prefix, ...), but textwrap.fill of an empty string returns "" without emitting the initial_indent. So the "Usage: program " prefix gets dropped on the floor and only the trailing newline makes it through. Empty line, just like the issue.

So the fix just writes the prefix directly when there are no args, and only goes through wrap_text when there's something to wrap. The else-branch (prefix too long) doesn't hit this because it already writes usage_prefix before the wrap call.

Added a regression test using the reporter's repro.

@davidism davidism closed this May 10, 2026
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

2 participants