Skip to content

Add typing.TypeForm overloads to tyro.cli() signature#461

Merged
brentyi merged 4 commits into
mainfrom
brent/20260428_typeform
Apr 30, 2026
Merged

Add typing.TypeForm overloads to tyro.cli() signature#461
brentyi merged 4 commits into
mainfrom
brent/20260428_typeform

Conversation

@brentyi
Copy link
Copy Markdown
Owner

@brentyi brentyi commented Apr 29, 2026

PEP 747 was finally accepted this past February, will be included in Python 3.15, and has been backported via typing_extensions.

This PR includes TypeForm in overloads for tyro.cli(). This fixes issues like #460.

For more context, see this comment (from 2022!):

tyro/tyro/_typing.py

Lines 1 to 14 in 5f1b975

# tyro's API relies heavily on parsing type annotations, which may be both "regular"
# types like `int`, `str`, and classes, or more general forms like `int | str` or
# `Annotated[str, ...]`.
#
# To correctly annotate variables that can take these more general type forms, we need
# to wait for a typing.TypeForm PEP:
# https://github.com/python/mypy/issues/9773
#
# This doesn't yet exist, so in the meantime we use Type[T] everywhere we would
# otherwise have TypeForm[T]. This mostly works, and fortunately is supported by pyright
# and pylance (relevant: https://github.com/microsoft/pyright/issues/4298), but should
# be switched for the correct typing.TypeForm annotation once it's available.
from typing import Type as TypeForm

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (2cb43d7) to head (e9b8c1b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #461      +/-   ##
==========================================
- Coverage   99.64%   99.64%   -0.01%     
==========================================
  Files          52       51       -1     
  Lines        3984     3974      -10     
==========================================
- Hits         3970     3960      -10     
  Misses         14       14              
Flag Coverage Δ
unittests 99.64% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brentyi brentyi merged commit f6db70a into main Apr 30, 2026
19 checks passed
@brentyi brentyi deleted the brent/20260428_typeform branch April 30, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant