hooks
Utility functions for hook argument and output manipulation.
Functions:
Name | Description |
---|---|
get_arg_by_name_or_index |
Get the argument by name or index. |
set_arg_by_name_or_index |
Set the argument by name or index. |
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 |
---|---|---|---|
|
tuple[Any, ...]
|
The positional arguments. |
required |
|
dict[str, Any]
|
The keyword arguments. |
required |
|
str | None
|
The name of the argument to get. |
required |
|
int | None
|
The index of the argument to get. |
required |
Raises:
Type | Description |
---|---|
IndexError
|
If |
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 |
---|---|---|---|
|
tuple[Any, ...]
|
The positional arguments. |
required |
|
dict[str, Any]
|
The keyword arguments. |
required |
|
str | None
|
The name of the argument to set. |
required |
|
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 |
required |
|
Any
|
The new argument value. |
required |
Raises:
Type | Description |
---|---|
IndexError
|
If |
Returns:
Type | Description |
---|---|
tuple[tuple[Any, ...], dict[str, Any]]
|
The modified args and kwargs. |