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.
- 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 validatedignore_return (
bool
, default:False
) – whether or not to ignore the return annotationignore_args (
Optional
[Set
[str
]], default:None
) – any arguments that should be ignoredtypehint_resolver (
Callable
[[Any
],Validator
[Any
]], default:<function resolve_signature_typehint_default at 0x7f3252b00180>
) – the function responsible for resolving type annotations tokoda_validate.Validator
soverrides (
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