neuralib.argp.core.Argument
- class neuralib.argp.core.Argument[source]
Bases:
objectDescriptor (https://docs.python.org/3/glossary.html#term-descriptor). Carried the arguments pass to
argparse.ArgumentParser.add_argument.Creation
Use
argument().>>> class Example: ... a: str = argument('-a')
- __init__(*options, validator=None, validate_on_set=None, group=None, ex_group=None, hidden=False, **kwargs)[source]
- Parameters:
options – options
group (str | None) – argument group.
ex_group (str | None) – mutually exclusive group.
kwargs
validator (Callable[[T], bool] | None)
validate_on_set (bool | None)
hidden (bool)
Methods
__init__(*options[, validator, ...])add_argument(ap, instance)Add this into argparse.ArgumentParser.
infer missing keywords.
with_options([option, action, nargs, const, ...])Modify or update keyword parameter and return a new argument.
Attributes
- __init__(*options, validator=None, validate_on_set=None, group=None, ex_group=None, hidden=False, **kwargs)[source]
- Parameters:
options – options
group (str | None) – argument group.
ex_group (str | None) – mutually exclusive group.
kwargs
validator (Callable[[T], bool] | None)
validate_on_set (bool | None)
hidden (bool)
- property default
- property const
- property metavar: str | None
- property choices: tuple[str, ...] | None
- property required: bool
- property help: str | None
- add_argument(ap, instance)[source]
Add this into argparse.ArgumentParser.
- Parameters:
ap (ArgumentParser)
instance
- Returns:
- with_options(option: str | dict[str, str] = None, *options: str, action: Literal['store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'extend', 'count', 'help', 'version', 'boolean'] = None, nargs: int | Literal['*', '+', '?', '...'] = None, const: T = None, default: T = None, type: Type | Callable[[str], T] = None, validator: Callable[[T], bool] = None, validate_on_set: bool = None, choices: Sequence[str] = None, required: bool = None, hidden: bool = None, help: str = None, group: str = None, metavar: str = None) Argument[source]
Modify or update keyword parameter and return a new argument.
option flags update rule:
(): do not update options('-a', '-b'): replace options(..., '-c'): append options({'-a': '-A'}): rename options({'-a': '-A'}, ...): rename options, keep options if not in the dict.
general form:
() | (dict?, ...?, *str)- Parameters:
options – change option flags
kwargs – change keyword parameters, use … to unset parameter
- Returns: