Skip to content

hooks

Utility functions for hook argument and output manipulation.

get_arg_by_name_or_index

get_arg_by_name_or_index(args: tuple[Any, ...], kwargs: dict[str, Any], name: str | None, idx: int | None) -> Any

Get the argument by name or index.

This function will prioritize returning the argument by index over by name.

Parameters:

Name Type Description Default
args tuple[Any, ...]

The positional arguments.

required
kwargs dict[str, Any]

The keyword arguments.

required
name str | None

The name of the argument to get.

required
idx int | None

The index of the argument to get.

required

Raises:

Type Description
IndexError

If idx is negative or out of bounds for args.

Returns:

Type Description
Any

The argument.

set_arg_by_name_or_index

set_arg_by_name_or_index(args: tuple[Any, ...], kwargs: dict[str, Any], name: str | None, idx: int | None, arg: Any) -> tuple[tuple[Any, ...], dict[str, Any]]

Set the argument by name or index.

Parameters:

Name Type Description Default
args tuple[Any, ...]

The positional arguments.

required
kwargs dict[str, Any]

The keyword arguments.

required
name str | None

The name of the argument to set.

required
idx int | None

The index of the argument to set. The argument may be appended to the positional arguments, so the index may be up to the length of args.

required
arg Any

The new argument value.

required

Raises:

Type Description
IndexError

If idx is negative or out of bounds for args.

Returns:

Type Description
tuple[tuple[Any, ...], dict[str, Any]]

The modified args and kwargs.