Skip to content

Conversation

@svlandeg
Copy link
Member

@svlandeg svlandeg commented Nov 17, 2025

As stated in the docs, currently when an argument has a default and is thus not required (e.g. tutorial003.py), the help string shows the argument name between brackets when printing the help string:

python tutorial003.py --help
Usage: main.py [OPTIONS] [NAME]
...
Arguments:
[NAME] Who to greet [default: World]

However, when we use metavar to set a synonym for this argument, then suddenly it doesn't appear between brackets anymore, e.g. tutorial006.py

python tutorial003.py --help
Usage: main.py [OPTIONS] ✨username✨

Arguments:
✨username✨ [default: World]

This PR makes that consistent:

python tutorial006.py --help
Usage: main.py [OPTIONS] [✨username✨]

Arguments:
[✨username✨] [default: World]

Follow-up work

I'd love feedback on this, because I'm looking into a few more cases where metavar processing seems to be inconsistent, especially when combined with Rich formatting.

I also have questions around adding the type_var stuff at L394-403 in core.py, and whether that's actually used/documented anywhere in Typer. Those are probably follow-up discussions though, and this PR tries to single out a first fix before moving on.

[Update]: now also created #1410, which I would review after this one.

@svlandeg svlandeg added the bug Something isn't working label Nov 17, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

assert "[OPTIONS] ✨username✨" in result.output
assert "Usage: main [OPTIONS] [✨username✨]" in result.output
assert "Arguments" in result.output
assert "✨username✨" in result.output
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this second assert was always redundant, as L18 would already fail if this wasn't the case.

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.

1 participant