parse_arg_details#
- caf.toolkit.arguments.parse_arg_details(annotation)[source]#
Attempt to get argument type from annotation text.
This only works with basic Python types (int, str, float, bool and Path) for any other types str will be returned.
- Parameters:
annotation (str) – Type annotation to be parsed e.g. ‘list[int | str]’. This can also handle the repr of a type e.g. “<class ‘bool’>”.
- Returns:
type – Argument type, will use the most generic type if multiple options are given e.g. ‘int | str | float’ will return str.
bool – True if the type annotation is optional e.g. ‘Optional[str]’ or ‘str | None’. Otherwise False.
int | str | None – Number of arguments expected as required by nargs parameter in argparse.ArgumentParser.add_argument. This will return an int if the type is a tuple, ‘*’ for lists and None otherwise.
- Return type: