Skip to content

toolr.utils._signature

Utilities to parse function signatures.

VarArg

Bases: Arg, Struct

VarArg is a special case of Arg that is used to represent a variable number of arguments.

arg

arg(
    *,
    aliases: list[str] | None = None,
    required: bool | None = None,
    metavar: str | None = None,
    action: str | None = None,
    choices: list[Any] | None = None,
    nargs: NargsType | None = None,
    group: str | None = None,
) -> ArgumentAnnotation

Create an ArgumentAnnotation.

This function is meant to be used with :class:typing.Annotated to create an ArgumentAnnotation.

Parameters:

Name Type Description Default
aliases list[str] | None

Aliases for the argument.

None
required bool | None

Whether the argument is required.

None
metavar str | None

The metavar for the argument.

None
action str | None

The action for the argument.

None
choices list[Any] | None

The choices for the argument.

None
nargs NargsType | None

The number of arguments to accept.

None
group str | None

The name of the mutually exclusive group for the argument.

None
Source code in python/toolr/utils/_signature.py
def arg(
    *,
    aliases: list[str] | None = None,
    required: bool | None = None,
    metavar: str | None = None,
    action: str | None = None,
    choices: list[Any] | None = None,
    nargs: NargsType | None = None,
    group: str | None = None,
) -> ArgumentAnnotation:
    """
    Create an ArgumentAnnotation.

    This function is meant to be used with :class:`typing.Annotated` to create an ArgumentAnnotation.

    Args:
        aliases: Aliases for the argument.
        required: Whether the argument is required.
        metavar: The metavar for the argument.
        action: The action for the argument.
        choices: The choices for the argument.
        nargs: The number of arguments to accept.
        group: The name of the mutually exclusive group for the argument.
    """
    return ArgumentAnnotation(
        aliases=aliases,
        required=required,
        metavar=metavar,
        action=action,
        choices=choices,
        nargs=nargs,
        group=group,
    )