Reference¶
Behold the non-API of beartype!
Beartype.
For PEP 8 compliance, this namespace exposes a subset of the metadata constants
provided by the top-level meta
submodule commonly inspected by external
automation.
-
beartype.
__version__
= '0.5.2'¶ Human-readable package version as a
.
-delimited string.For PEP 8 compliance, this specifier has the canonical name
__version__
rather than that of a typical global (e.g.,VERSION_STR
).
-
beartype.
__version_info__
= (0, 5, 2)¶ Machine-readable package version as a tuple of integers.
For PEP 8 compliance, this specifier has the canonical name
__version_info__
rather than that of a typical global (e.g.,VERSION_PARTS
).
-
beartype.
beartype
(func)[source]¶ 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 reduces to a noop.- Parameters
func (CallableTypes) – Non-class callable (i.e., callable object that is not a class) to be decorated by a dynamically generated new callable wrapping this original callable with pure-Python type-checking.
- Returns
Dynamically generated new callable wrapping this original callable with pure-Python type-checking.
- Return type
CallableTypes
- Raises
BeartypeDecorHintException – If any annotation on this callable is neither: * A PEP-compliant type (i.e., instance or class complying with a PEP supported by
beartype
), including: * `PEP 484`_ types (i.e., instance or class declared by the stdlibtyping
module). * A PEP-noncompliant type (i.e., instance or class complying withbeartype
-specific semantics rather than a PEP), including: * Fully-qualified forward references (i.e., strings specified as fully-qualified classnames). * Tuple unions (i.e., tuples containing one or more classes and/or forward references).BeartypeDecorParamNameException – If the name of any parameter declared on this callable is prefixed by the reserved substring
__beartype_
.BeartypeDecorHintPep563Exception – If `PEP 563`_ is active for this callable and evaluating a postponed annotation (i.e., annotation whose value is a string) on this callable raises an exception (e.g., due to that annotation referring to local state no longer accessible from this deferred evaluation).
BeartypeDecorWrappeeException – If this callable is either uncallable or a class.
. _PEP 484: – https://www.python.org/dev/peps/pep-0484
. _PEP 563: – https://www.python.org/dev/peps/pep-0563