fix: Improve metavar display consistency in Rich help output#1607
Closed
by22Jy wants to merge 2 commits intofastapi:masterfrom
Closed
fix: Improve metavar display consistency in Rich help output#1607by22Jy wants to merge 2 commits intofastapi:masterfrom
by22Jy wants to merge 2 commits intofastapi:masterfrom
Conversation
Issue: fastapi#1156 Problem: When using Rich help output, Arguments with custom metavar show inconsistent behavior. The metavar appears in the parameter name column instead of being displayed as the parameter name, making it look like a type annotation. Solution: - Smart detection of custom vs default metavar for Arguments - For Arguments with custom metavar: use metavar as name, show type in type column - For Arguments without custom metavar: preserve original behavior - Non-breaking: only affects Arguments with custom metavar Testing: - All 210 related tests pass - Verified with both required and optional arguments Example: Before (confusing): Arguments: * user MY_ARG [required] <- metavar looks like type After (correct): Arguments: * MY_ARG TEXT [required] <- metavar as name, type shown correctly
svlandeg
reviewed
Feb 24, 2026
Member
svlandeg
left a comment
There was a problem hiding this comment.
I'm going to close this. Feel free to review #1410 if you think something is wrong with that approach. That PR contains a lot more background information, examples, and unit tests, and was already recorded as a solution to #1156. Reviewing different PRs (especially when they're not complete, i.e. lacking unit tests) for the same issue creates too much maintenance burden.
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
Improves the consistency of metavar display in Rich help output for Arguments with custom metavar.
Problem
When using Rich help output, Arguments with custom metavar show inconsistent behavior:
Before (confusing):
The metavar
userappears in the parameter name column, making it look like a type annotation.Solution
Smart detection of custom vs default metavar:
After (correct):
Changes
typer/rich_utils.pyto detect custom metavar for ArgumentsTesting
Related
metavar#1410 (addresses same issue with different approach)Checklist