tyro.constructors._registry
¶
Module Contents¶
- tyro.constructors._registry.current_registry: ConstructorRegistry | None¶
- tyro.constructors._registry.PrimitiveSpecRule¶
- tyro.constructors._registry.StructSpecRule¶
- tyro.constructors._registry.check_default_instances() bool [source]¶
Check whether we should be strict about checking that default types and instances match.
This is usually False; tyro attempts to be somewhat lenient when inconsistent types are encounted. Strictness, however, is useful for matching annotated subcommands to default values.
- Return type:
- tyro.constructors._registry.check_default_instances_context()[source]¶
Context for whether we should be strict about checking that default types and instances match.
This is usually False; tyro attempts to be somewhat lenient when inconsistent types are encounted. Strictness, however, is useful for matching annotated subcommands to default values.
- class tyro.constructors._registry.ConstructorRegistry[source]¶
Registry for rules that define how types are constructed from command-line arguments.
The behavior of CLIs generated by tyro are based on two types of rules.
Primitive rules should be a callable with the signature:
where None is returned if the rule doesn’t apply, and UnsupportedTypeAnnotationError is returned if the rule applies but an error was encountered. Each primitive rule defines behavior for a type that can be instantiated from a single command-line argument.
Struct rules should be a callable with the signature:
where None is returned if the rule doesn’t apply. Each struct rule defines behavior for a type that can be instantiated from multiple command-line arguments.
To activate a registry, use it as a context manager. For example:
- primitive_rule(rule: PrimitiveSpecRule) PrimitiveSpecRule [source]¶
Define a rule for constructing a primitive type from a string. The most recently added rule will be applied first.
Custom primitive rules will take precedence over both default primitive rules and struct rules
- Parameters:
rule (PrimitiveSpecRule)
- Return type:
PrimitiveSpecRule
- struct_rule(rule: StructSpecRule) StructSpecRule [source]¶
Define a rule for constructing a primitive type from a string. The most recently added rule will be applied first.
- Parameters:
rule (StructSpecRule)
- Return type:
StructSpecRule
- classmethod get_primitive_spec(type_info: tyro.constructors._primitive_spec.PrimitiveTypeInfo, nondefault_only: bool = False) tyro.constructors._primitive_spec.PrimitiveConstructorSpec | tyro.constructors._primitive_spec.UnsupportedTypeAnnotationError [source]¶
Get a constructor specification for a given type.
- Parameters:
type_info (tyro.constructors._primitive_spec.PrimitiveTypeInfo)
nondefault_only (bool)
- Return type:
tyro.constructors._primitive_spec.PrimitiveConstructorSpec | tyro.constructors._primitive_spec.UnsupportedTypeAnnotationError
- classmethod get_struct_spec(type_info: tyro.constructors._struct_spec.StructTypeInfo) tyro.constructors._struct_spec.StructConstructorSpec | None [source]¶
Get a constructor specification for a given type. Returns None if unsuccessful.
- Parameters:
type_info (tyro.constructors._struct_spec.StructTypeInfo)
- Return type: