Skip to content

馃悰 Ensure that the default option name is not changed by setting a metavar - #1957

Open
svlandeg wants to merge 2 commits into
fastapi:masterfrom
svlandeg:fix/metavar
Open

svlandeg wants to merge 2 commits into
fastapi:masterfrom
svlandeg:fix/metavar

Conversation

@svlandeg

@svlandeg svlandeg commented Sep 14, 2026

Copy link
Copy Markdown
Member

Pull Request

Discussion: #1900

Description

Metavar annotations aren't supposed to influence the display/usage of the option name, as demonstrated by the test test_parameter_metavar which ensures that name: Annotated[str, typer.Option(metavar="CUSTOM") is called with --name.

A recent PR #1863 (released with 0.27.0) introduced a small regression on this behaviour, where a metavar corresponding to the option name (if both were lower-cased) could actually overwrite the casing. In retrospect, and after studying the reports & arguments in #1900, I think this was a bug/mistake on my end.

This PR fixes things to make the rule consistent: metavars are only for display (as already documented) and should never influence how an option is used.

鈿狅笍 Note that this is breaking behaviour compared to 0.27.0 鈿狅笍
(while being less breaking with the original 0.26.8 behaviour)

AI Disclaimer

Used Cursor as a sparring partner to check my understanding & reasoning, we agreed on all edits in this PR 馃檪

Checklist

  • This PR links to a GitHub Discussion for the proposed code change.
  • I added tests for the change.
  • The new or updated tests fail on the main branch and pass on this PR.
  • Coverage stays at 100%.
  • The documentation explains the change if needed.

@svlandeg svlandeg added the bug Something isn't working label Sep 14, 2026
Comment thread tests/test_core.py
"--arg6",
"6",
"--ARG9",
"--arg9",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I actually think this was the originally intended behaviour of the test, as the print-out on L399 has arg9, not ARG9 (while ARG4 upper-cased does make sense)

@svlandeg
svlandeg marked this pull request as ready for review September 14, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants