Skip to content

💥 Update metavar printing - #1863

Merged
tiangolo merged 50 commits into
fastapi:masterfrom
svlandeg:feat/metavar
Jul 15, 2026
Merged

💥 Update metavar printing#1863
tiangolo merged 50 commits into
fastapi:masterfrom
svlandeg:feat/metavar

Conversation

@svlandeg

@svlandeg svlandeg commented Jun 27, 2026

Copy link
Copy Markdown
Member

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 in the usage string
  • {} for referencing an object (i.e. not a literal string) in the usage string if neither of the other 2 apply
  • AVOID ALL CAPS

Breaking changes

  • metavar types now show up as the actual Python type 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.
  • 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.
  • In the help usage strings, parameter/metavar names are now put between brackets{}, unless they're already surrounded with the "optional" denoting brackets [].
  • In the list of "Arguments:", no brackets are printed around the names (on master, optional ones were enclosed with [] which felt inconsistent with optional options)

Edits in custom.js

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.

Tangiantel fixes

  • 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:
  • I found some other issues with the docs while going through everything in detail, and decided to fix those in this PR as well. Things like defaults not displayed in the example output, or the Arguments list missing, etc. I'm guessing these were mostly manual copy/paste errors from the past 🤷‍♀️

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.

The Python edits 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". Only the docs & tests changes will be brought over from here - the code changes from this PR will be subsumed by PR 1831.

AI Disclaimer

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

Checklist

  • 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/tutorial has been updated to reflect the new help formatting

@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 00e76e0 at: https://57e738c4.typertiangolo.pages.dev

Modified Pages

Comment thread docs_src/parameter_types/number/tutorial001_an_py310.py
@svlandeg
svlandeg marked this pull request as ready for review July 14, 2026 18:46
@svlandeg svlandeg removed their assignment Jul 14, 2026

@tiangolo tiangolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Everything looks good! 🙌

This must have been painful to make, going through all the docs. 😅

Thank you!

@tiangolo
tiangolo merged commit 42196d4 into fastapi:master Jul 15, 2026
24 checks passed
@svlandeg
svlandeg deleted the feat/metavar branch July 15, 2026 19:31
@svlandeg

svlandeg commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

This must have been painful to make, going through all the docs. 😅

Quite 😅

Had to do several sections multiple times, too, after making fixes and going back to make sure everything was consistent 🙈

llewelld added a commit to alan-turing-institute/data-safe-haven that referenced this pull request Jul 28, 2026
In release 0.27.0 Typer introduced breaking changes in the way metavars
are output:

https://github.com/fastapi/typer/releases

In particular, objects are now surrounded by {braces} in usage strings.
See the following PR:

fastapi/typer#1863

This broke one of our tests, which expected to see the string
"Usage: run [OPTIONS] SRE_NAME COMMAND" in stdout but in fact received
the string "Usage: run [OPTIONS] {sre_name} {command}".

This change updates the test to expect the new string, which is
correctly following the updated Typer rules.
llewelld added a commit to alan-turing-institute/data-safe-haven that referenced this pull request Jul 28, 2026
In release 0.27.0 Typer introduced breaking changes in the way metavars
are output:

https://github.com/fastapi/typer/releases

In particular, objects are now surrounded by {braces} in usage strings.
See the following PR:

fastapi/typer#1863

This broke one of our tests, which expected to see the string
"Usage: run [OPTIONS] SRE_NAME COMMAND" in stdout but in fact received
the string "Usage: run [OPTIONS] {sre_name} {command}".

This change updates the test to expect the new string, which is
correctly following the updated Typer rules.
llewelld added a commit to alan-turing-institute/data-safe-haven that referenced this pull request Jul 28, 2026
Updates the Myst parser so that it aligns with the updated sphinx.
Without this change the "colon_fence" plugin causes the documentation
build to fail.

Adjusts StorageAccountListKeysResult usage for AzureSdk 25.0.0. AzureSdk
25.0.0 (2026-05-19) introduced breaking changes to
StorageAccountListKeysResult. This change adjusts the code to
accommodate this.

See the AzureSDK ChangeLog:

https://github.com/Azure/azure-sdk-for-python/blob/42f59593caec801dabfe3d222ddb8561b46b5e72/sdk/storage/azure-mgmt-storage/CHANGELOG.md

Updates tests to accommodate breaking changes in Typer. In release
0.27.0 Typer introduced breaking changes in the way metavars are output:

https://github.com/fastapi/typer/releases

In particular, objects are now surrounded by {braces} in usage strings.
See the following PR:

fastapi/typer#1863

This broke one of our tests, which expected to see the string
"Usage: run [OPTIONS] SRE_NAME COMMAND" in stdout but in fact received
the string "Usage: run [OPTIONS] {sre_name} {command}".

This change updates the test to expect the new string, which is
correctly following the updated Typer rules.

Fixes a linter error. Switches from using single to double quotes to
denote a specific string, in order to pass the linter checks.
d3rky added a commit to softwareone-platform/mpt-tool that referenced this pull request Aug 4, 2026
…SDK (#95)

🤖 AI-generated PR — Please review carefully.

## Problem

mpt-tool 6.0.3 cannot be installed alongside `mpt-extension-sdk` 6.6.x,
so extension repos cannot pick up SDK 6.6.2. Resolution fails outright:

> `mpt-extension-sdk==6.6.1 depends on typer==0.26.*` and
`mpt-tool==6.0.3 depends on typer==0.27.*`, we can conclude that [they
are] incompatible.

The cap is not arbitrary: `mrok` (latest 0.10.5, a dependency of the
SDK) requires `typer<0.27.0,>=0.26.0`, and the SDK keeps
mrok/fastapi/typer pinned in lockstep for that reason (MPT-22658). The
SDK cannot move to typer 0.27 until mrok lifts its cap — mpt-tool has no
such constraint of its own, so it is the side that should hold.

typer reached 0.27 here through an unreviewed Dependabot bump (commit
`0e9b43e`, 2026-07-27), which touched only `pyproject.toml` and
`uv.lock` — nothing in mpt-tool actually needed 0.27.

## What was done

- `pyproject.toml`: `typer==0.27.*` → `==0.26.*`, with a comment
recording why the cap exists. `mpt-api-client==6.4.*` is left untouched.
- `uv.lock`: refreshed — typer 0.27.0 → 0.26.8. Nothing else moves.
- `.github/dependabot.yml`: ignore `typer >=0.27` so the next scheduled
run cannot silently reintroduce the conflict. This mirrors the guard the
SDK already carries for the same reason.

Reverting typer is behaviourally safe: the only breaking change in
0.27.0 is metavar rendering in `--help` output
([typer#1863](fastapi/typer#1863)) — types shown
as `<str>` instead of `TEXT`, choices as `<a|b>` instead of `[a|b]` —
and 0.27.1 only adjusts epilog formatting. No API or argument-parsing
changes. mpt-tool declares its metavars explicitly in `mpt_tool/cli.py`,
which both versions honour.

## Testing

- `ruff format --check`, `ruff check`, `flake8`, `mypy`, `uv lock
--check` all pass.
- Full test suite passes (54 tests) — no test expectations needed
changing in either direction.
- End-to-end resolution check in a scratch project depending on this
branch plus `mpt-extension-sdk[azure-monitor]==6.6.*` and
`mpt-extension-contrib-custom-notifications[teams]==1.2.*` resolves
cleanly to **SDK 6.6.2** with mpt-api-client 6.4.0 and typer 0.26.8,
confirming no further hidden conflict.

## Follow-up

This needs a release (6.0.4) to reach PyPI before extensions can move to
SDK 6.6.2; the currently published 6.0.3 stays unusable with 6.6.x. Once
mrok lifts its `typer<0.27` cap, the ignore rule here and in the SDK can
both be dropped and the two can move up together.

Jira: [MPT-23808](https://softwareone.atlassian.net/browse/MPT-23808)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

[MPT-23808]:
https://softwareone.atlassian.net/browse/MPT-23808?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

- Update `mpt-tool` to use `typer 0.26.*`.
- Update `uv.lock` to `typer 0.26.8`.
- Prevent Dependabot from updating `typer` to version `0.27` or later.
- Enable installation with `mpt-extension-sdk` 6.6.x.
- Release version 6.0.4 to publish the fix.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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