github beartype/beartype v0.3.0
Stable Release v0.3.0

latest releases: v0.18.5, v0.18.4, v0.18.3...
3 years ago

Beartype 0.3.0

Changes include:

Compatibility Broken

  • None. This release preserves backward compatibility with the prior
    stable release.

Dependencies Bumped

  • None. Not that we had any dependencies to begin with, of course.

Features Added

  • Deep sequence type-checking. The @beartype.beartype decorator
    now type-checks both the shallow types and deep contents of
    parameters and return values annotated with typing-based sequences
    in guaranteed constant time, exploiting a variant of the well-known
    coupon collector's problem by randomly type-checking one item at each
    nesting level of each sequence on each call of each decorated
    callable. Currently supported typing-based sequences include:
    • typing.List.
    • typing.MutableSequence.
    • typing.Sequence.
  • Human-readable exception messages on type-checking failures. When
    passed parameters or returning values violating PEP-compliant type
    hints, callables decorated by the @beartype.beartype decorator now
    raise human-readable exceptions exhibiting the exact cause(s) of those
    violations, including violations deeply nested in subcontainers (e.g.,
    "@beartyped pep_hinted() parameter pep_hinted_param=[([37],)]
    violates PEP type hint
    typing.List[typing.Sequence[typing.MutableSequence[str]]], as list
    item 0 tuple item 0 list item 0 value "37" not str.") Currently
    supported typing type hints that now generate human-readable
    exception messages include:
    • typing.List.
    • typing.MutableSequence.
    • typing.Optional.
    • typing.Sequence.
    • typing.Union.

Features Optimized

  • Deep sequence type-checking. Under Python >= 3.8, the
    @beartype.beartype decorator generates optimal code deeply
    type-checking items contained in nested subsequences (e.g.,
    List[List[List[str]]]) with PEP 572-style assignment expressions --
    the controversial syntactic change that would prompt Guido to
    voluntarily abdicate his ancestral leadership role as BDFL. Thanks to
    beartype 0.3.0, assignment expressions have finally proved their
    real-world utility. This optimization has been quantitatively profiled
    to generate type-checking code at least twice as fast as the
    equivalent code generated under Python < 3.8 in the case of
    triply-nested sequences. Since this performance gap only increases as
    the nesting level increases, a doubling of performance is only the
    minimum improvement observable under Python >= 3.8. Sequences more
    than triply-nested can expect a comparably dramatic speedup.
  • User-defined callables not accepting positional arguments. A
    local variable previously unconditionally defined in the bodies of all
    wrapper functions dynamically generated and returned by the
    @beartype.beartype decorator is now only conditionally defined in
    the bodies of wrapper functions wrapping user-defined callables
    accepting one or more positional arguments.
  • Wrapper function generation. Wrapper functions are now confined to
    internally access only the exact set of global attributes they
    specifically require rather than the complete set of such attributes
    accessible from the private beartype._decor.main submodule.

Features Deprecated

  • None. You don't deprecate what ain't broke.

Features Removed

  • None. You don't remove what's worth keepin'.

Tests Improved

  • Deep type-checking. Exhaustive tests guaranteeing the sanity of
    deep type-checking of all supported combinations of typing sequences
    and typing unions have been added.
  • Human-readable exception messages on type-checking failures.
    Exhaustive tests guaranteeing the readability of these messages have
    also been added by iteratively matching these messages against
    iterables of arbitrary regular expressions expected to both match and
    not match these messages.

Documentation Revised

  • Installation instructions, including new Gentoo-specific
    installation instructions courtesy the third-party raiagent overlay.

API Changed

  • Nothing. Not publicly, anyway. Violate privacy encapsulation and
    the cuddly kitten gets it!

(Spherical orthodontics adhere to a glib gibberings of orthopedic ornithopters!)

Don't miss a new beartype release

NewReleases is sending notifications on new releases.