tyro._parsers

Interface for generating argparse.ArgumentParser() definitions from callables.

Module Contents

tyro._parsers.T
class tyro._parsers.ParserSpecification[source]

Each parser contains a list of arguments and optionally some subparsers.

f: Callable
description: str
args: List[tyro._arguments.ArgumentDefinition]
field_list: List[tyro._fields.FieldDefinition]
child_from_prefix: Dict[str, ParserSpecification]
helptext_from_intern_prefixed_field_name: Dict[str, str | None]
subparsers: SubparsersSpecification | None
subparsers_from_intern_prefix: Dict[str, SubparsersSpecification]
intern_prefix: str
extern_prefix: str
has_required_args: bool
consolidate_subcommand_args: bool
static from_callable_or_type(f: Callable[Ellipsis, T], markers: Set[tyro.conf._markers._Marker], description: str | None, parent_classes: Set[Type[Any]], default_instance: T | tyro._singleton.PropagatingMissingType | tyro._singleton.NonpropagatingMissingType, intern_prefix: str, extern_prefix: str, subcommand_prefix: str = '', support_single_arg_types: bool = False) ParserSpecification[source]

Create a parser definition from a callable or type.

Parameters:
Return type:

ParserSpecification

apply(parser: tyro._argparse.ArgumentParser) Tuple[tyro._argparse.ArgumentParser, Ellipsis][source]

Create defined arguments and subparsers.

Parameters:

parser (tyro._argparse.ArgumentParser)

Return type:

Tuple[tyro._argparse.ArgumentParser, Ellipsis]

apply_args(parser: tyro._argparse.ArgumentParser, parent: ParserSpecification | None = None) None[source]

Create defined arguments and subparsers.

Parameters:
Return type:

None

tyro._parsers.handle_field(field: tyro._fields.FieldDefinition, parent_classes: Set[Type[Any]], intern_prefix: str, extern_prefix: str, subcommand_prefix: str) tyro._arguments.ArgumentDefinition | ParserSpecification | SubparsersSpecification[source]

Determine what to do with a single field definition.

Parameters:
Return type:

Union[tyro._arguments.ArgumentDefinition, ParserSpecification, SubparsersSpecification]

class tyro._parsers.SubparsersSpecification[source]

Structure for defining subparsers. Each subparser is a parser with a name.

name: str
description: str | None
parser_from_name: Dict[str, ParserSpecification]
intern_prefix: str
required: bool
default_instance: Any
options: Tuple[tyro._typing.TypeForm[Any] | Callable, Ellipsis]
static from_field(field: tyro._fields.FieldDefinition, parent_classes: Set[Type[Any]], intern_prefix: str, extern_prefix: str) SubparsersSpecification | None[source]
Parameters:
Return type:

Optional[SubparsersSpecification]

apply(parent_parser: tyro._argparse.ArgumentParser) Tuple[tyro._argparse.ArgumentParser, Ellipsis][source]
Parameters:

parent_parser (tyro._argparse.ArgumentParser)

Return type:

Tuple[tyro._argparse.ArgumentParser, Ellipsis]

tyro._parsers.add_subparsers_to_leaves(root: SubparsersSpecification | None, leaf: SubparsersSpecification) SubparsersSpecification[source]
Parameters:
Return type:

SubparsersSpecification

tyro._parsers.none_proxy() None[source]
Return type:

None