What’s supported¶
For minimum-boilerplate CLIs, tyro
aims to maximize support of
Python’s standard typing
features.
As a partial list, inputs can be annotated with:
Union types, like
X | Y
,typing.Union
, andtyping.Optional
.typing.Literal
andenum.Enum
.Type aliases, for example using Python 3.12’s PEP 695 type statement.
Generics, such as those annotated with
typing.TypeVar
or with the type parameter syntax introduced by Python 3.12’s PEP 695.Compositions of the above types, like
tuple[int | str, ...] | None
.
Types can also be placed and nested in various structures, such as:
attrs
,pydantic
, andflax.linen
models.typing.TypedDict
, flags liketotal=
, and associated annotations liketyping.Required
,typing.NotRequired
,typing.ReadOnly
,
What’s not supported¶
There are some limitations. We currently do not support:
Variable-length sequences over nested structures, unless a default is provided. For types like
list[Dataclass]
, we require a default value to infer length from. The length of the corresponding field cannot be changed from the CLI interface.Nesting variable-length sequences in other sequences.
tuple[int, ...]
andtuple[tuple[int, int, int], ...]
are supported, as the variable-length sequence is the outermost type. However,tuple[tuple[int, ...], ...]
is ambiguous to parse and not supported.Self-referential types, like
type RecursiveList[T] = T | list[RecursiveList[T]]
.
In each of these cases, a custom constructor can be defined as a workaround.