aspis.internal.errors.arity_error

Exceptions

ArityError(e)

Custom exception for handling function arity mismatches.

exception aspis.internal.errors.arity_error.ArityError(e)[source]

Custom exception for handling function arity mismatches.

ArityError parses TypeError exceptions to determine if they’re caused by incorrect function arity (wrong number of arguments). It categorizes errors as under-application (too few arguments) or over-application (too many arguments), and tracks whether the error involves keyword arguments.

is_arity_error

True if the error is an arity-related TypeError.

Type:

bool

underapplied

True if too few arguments were provided.

Type:

bool

overapplied

True if too many arguments were provided.

Type:

bool

kwarg_error

True if the error involves keyword arguments.

Type:

bool

unexpected_kwargs

List of unexpected keyword argument names.

Type:

list

Example

>>> def foo(a, b):
...     return a + b
>>> try:
...     foo(1)
... except TypeError as e:
...     arity_err = ArityError(e)
...     print(arity_err.underapplied)
True
__init__(e)[source]

Initialize ArityError by parsing a TypeError exception.

Parameters:

e (Exception) – The exception to parse. Should be a TypeError from a function call with incorrect arity.

__bool__()[source]

Check if the error is a valid arity error.

Returns:

True if this is a recognized arity error, False otherwise.

Return type:

bool