koda_validate.signature#

exception InvalidArgsError(errs)#

Bases: Exception

Represents the validation failure of one or more arguments.

exception InvalidReturnError(err)#

Bases: Exception

Represents a return value that has failed validation.

resolve_signature_typehint_default(annotation)#
Return type:

Validator[Any]

validate_signature(func=None, *, ignore_return=False, ignore_args=None, typehint_resolver=<function resolve_signature_typehint_default>, overrides=None)#

Validates a function’s arguments and / or return value adhere to the respective typehints and / or any custom-specified Validation.Because we want to preserve the type signature of the function when it’s wrapped, we raise exceptions to represent failure (as opposed to returning ValidationResult[ReturnType], which would change the function’s type signature).

Parameters:
  • func (Optional[TypeVar(_DecoratedFunc, bound= Callable[..., Any])], default: None) – the function being validated

  • ignore_return (bool, default: False) – whether or not to ignore the return annotation

  • ignore_args (Optional[Set[str]], default: None) – any arguments that should be ignored

  • typehint_resolver (Callable[[Any], Validator[Any]], default: <function resolve_signature_typehint_default at 0x7fa8189e8180>) – the function responsible for resolving type annotations to koda_validate.Validators

  • overrides (Optional[Dict[Union[str, Tuple[Literal[‘return_key’]]], Validator[Any]]], default: None) – explicit Validator`s for arguments that takes priority over `typehint_resolver and Annotated types

Return type:

Union[TypeVar(_DecoratedFunc, bound= Callable[..., Any]), Callable[[TypeVar(_DecoratedFunc, bound= Callable[..., Any])], TypeVar(_DecoratedFunc, bound= Callable[..., Any])]]

Returns:

the decorated function