tyro.constructors._primitive_spec¶
Module Contents¶
- exception tyro.constructors._primitive_spec.UnsupportedTypeAnnotationError(message: tuple[tyro._fmtlib._Text, Ellipsis])[source]¶
Bases:
ExceptionException raised when a type annotation is not supported.
- Parameters:
message (tuple[tyro._fmtlib._Text, Ellipsis])
- tyro.constructors._primitive_spec.T¶
- class tyro.constructors._primitive_spec.PrimitiveTypeInfo[source]¶
Information used to generate constructors for primitive types.
- type: Type¶
Annotated field type. Forward references, aliases, and type variables/parameters will have been resolved and runtime annotations (typing.Annotated) will have been stripped.
- class tyro.constructors._primitive_spec.PrimitiveConstructorSpec[source]¶
Bases:
Generic[T]Specification for constructing a primitive type from a string.
There are two ways to use this class:
First, we can include it in a type signature via
typing.Annotated. This is the simplest for making local modifications to parsing behavior for individual fields.Alternatively, it can be returned by a rule in a
ConstructorRegistry.- nargs: int | tuple[int, Ellipsis] | Literal[*]¶
Number of arguments required to construct an instance. If nargs is “*”, then the number of arguments is variable. If nargs is a tuple, it represents multiple valid fixed argument counts (used for unions with different fixed nargs).
- instance_from_str: Callable[[list[str]], T]¶
Given a list of string arguments, construct an instance of the type. The length of the list will match the value of nargs.
- is_instance: Callable[[Any], bool | Literal[~]]¶
Given an object instance, does it match this primitive type? This is used for specific help messages when both a union type is present and a default is provided.
Can return “~” to signify that an instance is a “fuzzy” match, and should only be used if there are no other matches. This is used for numeric tower support.
- tyro.constructors._primitive_spec.apply_default_primitive_rules(registry: tyro.constructors._registry.ConstructorRegistry) None[source]¶
Apply default rules to the registry.
- Parameters:
- Return type:
None