processing.tools.beartype package¶
Submodules¶
@beartype decorator, implementing a rudimentary subset of PEP 484-style type checking based on Python 3.x function annotations.
See also
https
//stackoverflow.com/a/37961120/2809027 Stackoverflow answer introducing the @beartype decorator.
-
beartype
(func: callable) → callable¶ Decorate the passed callable (e.g., function, method) to validate both all annotated parameters passed to this callable _and_ the annotated value returned by this callable if any.
This decorator performs rudimentary type checking based on Python 3.x function annotations, as officially documented by PEP 484 (“Type Hints”). While PEP 484 supports arbitrarily complex type composition, this decorator requires _all_ parameter and return value annotations to be either:
Classes (e.g., int, OrderedDict).
Tuples of classes (e.g., (int, OrderedDict)).
If optimizations are enabled by the active Python interpreter (e.g., due to option -O passed to this interpreter), this decorator is a noop.
- Raises
NameError – If any parameter has the reserved name __beartype_func.
TypeError – If either: * Any parameter or return value annotation is neither: * A type. * A tuple of types. * The kind of any parameter is unrecognized. This should _never_ happen, assuming no significant changes to Python semantics.