ml.utils.argparse
Utilities for using argparse with dataclasses.
- ml.utils.argparse.get_type_from_string(type_name: str) Type [source]
Parses a type name to a string.
- Parameters:
type_name – The type name to parse.
- Returns:
The type corresponding to the type name.
- Raises:
ValueError – If the type name is not supported.
- ml.utils.argparse.add_args(parser: ArgumentParser, dc: Type[Config]) None [source]
Adds arguments to an argument parser from a dataclass.
- Parameters:
parser – The argument parser to add arguments to.
dc – The dataclass to add arguments from.
- Raises:
NotImplementedError – If the dataclass has a field with an unsupported type.
- ml.utils.argparse.from_args(args: Namespace, dc: Type[Config]) Config [source]
Creates a dataclass from an argument parser namespace.
- Parameters:
args – The argument parser namespace to create the dataclass from.
dc – The dataclass to create.
- Returns:
The dataclass created from the argument parser namespace.