Skip to content

Fix #1156: Argument metavar displays as name in rich help panel#1560

Closed
rodionsteshenko wants to merge 2 commits intofastapi:masterfrom
rodionsteshenko:fix-issue-1156
Closed

Fix #1156: Argument metavar displays as name in rich help panel#1560
rodionsteshenko wants to merge 2 commits intofastapi:masterfrom
rodionsteshenko:fix-issue-1156

Conversation

@rodionsteshenko
Copy link

Summary

Fixes #1156. When a custom metavar is set on an Argument (e.g. typer.Argument(metavar="MY_ARG")), the rich help panel now correctly shows:

  • Name column: the metavar (MY_ARG)
  • Type column: the actual type (TEXT, INTEGER, etc.)

Before (broken):

│ *    user      MY_ARG  [required]  │

After (fixed):

│ *  MY_ARG        TEXT  [required]  │

This matches the behavior of the non-rich help output and the usage line, where metavar replaces 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 column
  • tests/test_argument_metavar_rich.py: 3 test cases covering custom metavar display, default behavior, and non-string types

Test

Added test_argument_metavar_rich.py with three tests:

  1. test_argument_custom_metavar_shows_as_name_in_rich_help - verifies the fix
  2. test_argument_without_metavar_shows_default_name - regression guard for default behavior
  3. test_argument_metavar_with_int_type - verifies correct type display with custom metavar

Tests 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 coverage module failures unrelated to this change).

rodionsteshenko and others added 2 commits February 18, 2026 10:07
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.
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR!

I think this is already solved by PR #1410. Could you check out that branch and verify that it solves your issue?

@svlandeg
Copy link
Member

(I'll close this in the meantime, considering it as a duplicate)

@svlandeg svlandeg closed this Feb 18, 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.

Argument(metavar="MY_ARG") has different meaning for the arguments panel compared to the usage text or the non-rich help output

2 participants