tyro.constructors._struct_spec

Module Contents

class tyro.constructors._struct_spec.UnsupportedStructTypeMessage[source]

Reason why a callable cannot be treated as a struct type.

message: str
class tyro.constructors._struct_spec.InvalidDefaultInstanceError[source]

Return value when a default instance is not applicable to an annotated struct type.

message: tuple[tyro._fmtlib._Text, Ellipsis]
class tyro.constructors._struct_spec.StructFieldSpec[source]

Behavior specification for a single field in our callable.

name: str

The name of the field. This will be used as a keyword argument for the struct’s associated instantiate(**kwargs) function.

type: Type

The type of the field. Can be either a primitive or a nested struct type.

default: Any

The default value of the field.

helptext: str | Callable[[], str | None] | None

Helptext for the field.

is_default_overridden: None

Deprecated. No longer used.

class tyro.constructors._struct_spec.StructConstructorSpec[source]

Specification for a struct type, which is broken down into multiple fields.

Each struct type is instantiated by calling an instantiate(**kwargs) function with keyword a set of keyword arguments.

Unlike PrimitiveConstructorSpec, there is only one way to use this class. It must be returned by a rule in ConstructorRegistry.

instantiate: Callable[Ellipsis, Any]

Function to call to instantiate the struct.

fields: tuple[StructFieldSpec, Ellipsis]

Fields used to construct the callable. Each field is used as a keyword argument for the instantiate(**kwargs) function.

class tyro.constructors._struct_spec.StructTypeInfo[source]

Information used to generate constructors for struct types.

type: Type

The type of the (potential) struct.

markers: tuple[Any, Ellipsis]

Markers from tyro.conf that are associated with this field.

default: Any

The default value of the struct, or a member of tyro.constructors.MISSING_AND_MISSING_NONPROP if not present. In a function signature, this is X in def main(x=X): .... This can be useful for populating the default values of the struct.

in_union_context: bool

Flag indicating whether this type is being evaluated as part of a union. When True, allows collection types like List[Struct] or Dict[str, Struct] without defaults to be treated as struct types for subcommand creation.

static make(f: Type | Callable, default: Any, in_union_context: bool) → StructTypeInfo[source]
Parameters:
  • f (Type | Callable)

  • default (Any)

  • in_union_context (bool)

Return type:

StructTypeInfo

tyro.constructors._struct_spec.apply_default_struct_rules(registry: tyro.constructors._registry.ConstructorRegistry) → None[source]

Apply default struct rules to the registry.

This function registers all the struct rules for different types: - Dataclasses - TypedDict - Attrs classes - Dict - NamedTuple - Sequences - Tuples - Pydantic models

Parameters:

registry (tyro.constructors._registry.ConstructorRegistry)

Return type:

None