Fix #1156: Argument metavar displays as name in rich help panel#1560
Closed
rodionsteshenko wants to merge 2 commits intofastapi:masterfrom
Closed
Fix #1156: Argument metavar displays as name in rich help panel#1560rodionsteshenko wants to merge 2 commits intofastapi:masterfrom
rodionsteshenko wants to merge 2 commits intofastapi:masterfrom
Conversation
When a custom metavar is set on an Argument via typer.Argument(metavar=...), the rich help panel now correctly shows the metavar as the argument name and the actual type (e.g. TEXT, INTEGER) in the type column. Previously, the parameter name was shown in the name column and the metavar was incorrectly placed in the type column.
Member
|
(I'll close this in the meantime, considering it as a duplicate) |
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.
Summary
Fixes #1156. When a custom
metavaris set on anArgument(e.g.typer.Argument(metavar="MY_ARG")), the rich help panel now correctly shows:MY_ARG)TEXT,INTEGER, etc.)Before (broken):
After (fixed):
This matches the behavior of the non-rich help output and the usage line, where
metavarreplaces the argument name.Changes
typer/rich_utils.py: When a positional argument has a custom metavar, use it as the display name and show the type in the metavar columntests/test_argument_metavar_rich.py: 3 test cases covering custom metavar display, default behavior, and non-string typesTest
Added
test_argument_metavar_rich.pywith three tests:test_argument_custom_metavar_shows_as_name_in_rich_help- verifies the fixtest_argument_without_metavar_shows_default_name- regression guard for default behaviortest_argument_metavar_with_int_type- verifies correct type display with custom metavarTests 1 and 3 FAIL without the fix, PASS with it. Test 2 passes in both cases.
Tested locally on macOS ARM (Apple Silicon). Full test suite passes (excluding pre-existing
coveragemodule failures unrelated to this change).