Module aparse
None
None
Sub-modules
- aparse.argparse
- aparse.click
- aparse.core
- aparse.utils
Functions
AllArguments
def AllArguments(
x
)
ConditionalType
def ConditionalType(
typename,
fields=None,
*,
prefix: bool = True,
default=None,
**kwargs
)
ConditionalType allows aparse to condition its choices for a
specific parameter based on an argument. Usage:: class Model(ConditionalType): gpt2: GPT2 resnet: ResNet The type info can be accessed via the Model.annotations dict, and the Model.required_keys and Model.optional_keys frozensets. ConditionalType supports two additional equivalent forms: Model = ConditionalType(‘Model’, gpt2=GPT2, resnet=ResNet) Model = ConditionalType(‘Model’, dict(gpt2=GPT2, resnet=ResNet)) The class syntax is only supported in Python 3.6+, while two other syntax forms work for Python 2.7 and 3.2+
WithArgumentName
def WithArgumentName(
cls,
name=None
)
add_argparse_arguments
def add_argparse_arguments(
_fn=None,
*,
ignore: Set[str] = None,
before_parse: Callable[[argparse.ArgumentParser, Dict[str, Any]], argparse.ArgumentParser] = None,
after_parse: Callable[[argparse.Namespace, Dict[str, Any]], Dict[str, Any]] = None
)
Extends function or class with “add_argparse_arguments”, “from_argparse_arguments”, and “bind_argparse_arguments” methods.
“add_argparse_arguments” adds arguments to the argparse.ArgumentParser instance. “from_argparse_arguments” takes the argparse.Namespace instance obtained by calling parse.parse_args(), parses them and calls original function or constructs the class “bind_argparse_arguments” just parses the arguments into a kwargs dictionary, but does not call the original function. Instead, the parameters are returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore | None | Set of parameters to ignore when inspecting the function signature | None |
before_parse | None | Callback to be called before parser.parse_args() | None |
after_parse | None | Callback to be called before “from_argparse_arguments” calls the function and updates the kwargs. | |
Returns: The original function extended with other functions. | None |
register_handler
def register_handler(
handler
)
Classes
Handler
class Handler(
/,
*args,
**kwargs
)
Descendants
- aparse._handlers.DefaultHandler
- aparse._handlers.AllArgumentsHandler
- aparse._handlers.SimpleListHandler
- aparse._handlers.FromStrHandler
- aparse._handlers.WithArgumentNameHandler
- aparse._handlers.ConditionalTypeHandler
Methods
add_parameter
def add_parameter(
self,
parameter: aparse.core.ParameterWithPath,
parser: aparse.core.Runtime
) -> bool
bind
def bind(
self,
parameter: aparse.core.ParameterWithPath,
args: Dict[str, Any],
children: List[Tuple[aparse.core.Parameter, Any]]
) -> Tuple[bool, Any]
parse_value
def parse_value(
self,
parameter: aparse.core.ParameterWithPath,
value: Any
) -> Tuple[bool, Any]
preprocess_parameter
def preprocess_parameter(
self,
parameter: aparse.core.ParameterWithPath
) -> Tuple[bool, aparse.core.ParameterWithPath]
Literal
class Literal(
/,
*args,
**kwargs
)
Parameter
class Parameter(
name: Union[str, NoneType],
type: Union[Type, NoneType],
help: str = '',
children: List[ForwardRef('Parameter')] = <factory>,
default_factory: Union[Callable[[], Any], NoneType] = None,
choices: Union[List[Any], NoneType] = None,
argument_type: Union[Any, NoneType] = None,
_argument_name: Union[Tuple[str], NoneType] = None
)
Class variables
argument_type
choices
default_factory
help
Instance variables
default
Methods
enumerate_parameters
def enumerate_parameters(
self
)
find
def find(
self,
name: str
) -> Union[ForwardRef('Parameter'), NoneType]
replace
def replace(
self,
**kwargs
)
walk
def walk(
self,
fn: Callable[[ForwardRef('ParameterWithPath'), List[Any]], Any]
)
ParameterWithPath
class ParameterWithPath(
parameter: aparse.core.Parameter,
parent: Union[ForwardRef('ParameterWithPath'), NoneType] = None
)
Class variables
parent
Instance variables
argument_name
argument_type
children
choices
default
default_factory
full_name
help
name
type
Methods
find
def find(
self,
name
)
replace
def replace(
self,
**kwargs
)