Skip to content

💥 Update metavar printing#1863

Draft
svlandeg wants to merge 30 commits into
fastapi:masterfrom
svlandeg:feat/metavar
Draft

💥 Update metavar printing#1863
svlandeg wants to merge 30 commits into
fastapi:masterfrom
svlandeg:feat/metavar

Conversation

@svlandeg

@svlandeg svlandeg commented Jun 27, 2026

Copy link
Copy Markdown
Member

WIP: please don't review/comment yet 🙏

Description

We've decided to change a bit the "metavar" printing functionality of Typer. In short, the new rules are:

  • consistently use <> for displaying the type (including enum choices etc)
  • [] for displaying something optional
  • {} for referencing an object (i.e. not a literal string) if neither of the other 2 apply
  • AVOID ALL CAPS

Breaking changes

  • metavar types now show up as the Python type lowercased (without exception) and in <>, so "<str>" instead of "TEXT" and "<int>" instead of "INTEGER" etc.
  • Choices follow the same format so <simple|conv|lstm> instead of [simple|conv|lstm] or {simple|conv|lstm>}. Check the new test test_param_type_help_metavar for an overview.
  • metavar names are now cased as the declared name and put between brackets{} in the usage strings, unless they're already surrounded with the "optional" denoting brackets [].
  • parameter names are not magically lowercased or uppercased, they are just kept as declared in the Python code. cf. new test test_parameter_name_casing.

Tangiantel fix

  • While updating all docs, I realised that we didn't update them when we merged the fix to not display Default: None in the help text, PR 1120. I updated those as part of the documentation update here. I could also do this in a separate PR if preferred, but it would cause a lot of merge conflicts and duplicate work as I've now been going through all the docs in detail anyway.
  • Similarly, some docs still needed updating after PR 944 :hide-the-pain-emoji:

Documentation updates

When updating the documentation to show e.g. <str> instead of TEXT, this would be treated as an HTML tag and not actually displayed in our tutorial pages 😭 Hence the fixes to custom.js.

How to review this PR

Please mostly look at the test/documentation changes, and not so much the actual code changes in the Python files. Those will become obsolete with the Pydantic refactor that is in the works. In fact, this PR is a "spinoff" of the Pydantic refactor (#1831, WIP) in an attempt to make that one more "reviewable". The code changes here will be subsumed by that PR.

AI Disclaimer

Created through pair-programming with Cursor, manually reviewed in detail. Also went through all the Typer docs manually & in detail.

Checklist

@svlandeg svlandeg self-assigned this Jun 27, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

📝 Docs preview

Last commit df30ebc at: https://18f59613.typertiangolo.pages.dev

Modified Pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants