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.7.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, 7, 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: beartype._decor.main.T) beartype._decor.main.T[source]

Dynamically create and return a constant-time runtime type-checker (i.e., pure-Python function validating all parameters and returns of all calls to the passed pure-Python callable against all PEP-compliant type hints annotating those parameters and returns).

The type-checker returned by this decorator is:

  • Optimized uniquely for the passed callable.

  • Guaranteed to run in O(1) constant-time with negligible constant factors.

  • Type-check effectively instantaneously.

  • Add effectively no runtime overhead to the passed callable.

If optimizations are enabled by the active Python interpreter (e.g., due to option -O passed to this interpreter), this decorator silently reduces to a noop.

Parameters

func (Callable) – 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

Callable

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 stdlib typing module). * A PEP-noncompliant type (i.e., instance or class complying with beartype-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).

  • 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).

  • BeartypeDecorParamNameException – If the name of any parameter declared on this callable is prefixed by the reserved substring __beartype_.

  • BeartypeDecorWrappeeException – If this callable is either: * Uncallable. * A class, which beartype currently fails to support. * A C-based callable (e.g., builtin, third-party C extension).

  • BeartypeDecorWrapperException – If this decorator erroneously generates a syntactically invalid wrapper function. This should never happen, but here we are, so this probably happened. Please submit an upstream issue with our issue tracker if you ever see this. (Thanks and abstruse apologies!)

  • . _PEP 484:https://www.python.org/dev/peps/pep-0484

  • . _PEP 563:https://www.python.org/dev/peps/pep-0563