fix: keep write_usage output for commands without args#3365
fix: keep write_usage output for commands without args#3365d3v07 wants to merge 1 commit intopallets:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Click’s HelpFormatter.write_usage() behavior when called with no args, ensuring the “Usage:” prefix and program name are still emitted (regression for internal/interactive commands with no arguments).
Changes:
- Update
HelpFormatter.write_usage()to handle the no-args case without routing through the text wrapper. - Add a regression test for
write_usage("program")with defaultargs. - Document the fix in
CHANGES.rstunder 8.3.3.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/click/formatting.py |
Adds an early-return path to reliably render Usage: <prog> when args is empty. |
tests/test_formatting.py |
Adds a regression test asserting Usage: program\n for no-args usage rendering. |
CHANGES.rst |
Notes the bugfix and links to issue #3360. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| def test_help_formatter_write_usage_without_args(): | ||
| formatter = click.formatting.HelpFormatter() |
There was a problem hiding this comment.
For consistency within this test module, consider instantiating the formatter via the public alias click.HelpFormatter() (used in test_help_formatter_write_text) instead of reaching into click.formatting.HelpFormatter(). This keeps tests aligned with the intended public API surface.
| formatter = click.formatting.HelpFormatter() | |
| formatter = click.HelpFormatter() |
Fixes #3360
HelpFormatter.write_usage()routed emptyargsthrough the text wrapper, which produced an empty line and dropped the usage prefix entirely. Handle the no-args case directly soUsage: <prog>still renders for internal commands that take no arguments.This adds a regression test for
HelpFormatter.write_usage("program")and updatesCHANGES.rst.Verification
PYTHONPATH=src .venv/bin/pytest tests/test_formatting.py -q