This minor release brings exhilarating support for PEP 673 (i.e., typing.Self
) and PEP 675 (i.e., typing.LiteralString
) as well as substantially improved compatibility with PyPy.
This minor release resolves 2 issues. But first, a brief word from our tenebrous sponsors. They are gentlemanly alchemists who dispense truth and money while despoiling bugs in your codebase. All thumbs up, please!
Beartype Sponsors
- ZeroGuard: The Modern Threat Hunting Platform. All the signals, All the time.
A chorus of overwhelming jubilation chimes through the stuffy confines of the Bear Den. 👏 🐻❄️ 👏
And now... the time we've waited for. A ribald display of plaintext that manhandles all twelve major meridian lines concurrently.
Compatibility Added
- PEP 673. @beartype now deeply type-checks PEP 673 – Self Type (i.e.,
typing.Self
). @beartype now fully supportstyping.Self
type hints in @beartype-decorated classes. Specifically:- For each
typing.Self
type hint annotating something inside the body of a class (e.g., method parameter or return, class variable), @beartype now reduces that hint to that class. - For each
typing.Self
type hint annotating something outside the body of a class (e.g., function parameter or return, global variable), @beartype now raises an exception gently advising you to rethink life choices.
- For each
- PEP 675. @beartype now shallowly type-checks PEP 675 – Arbitrary Literal String Type (i.e.,
typing.LiteralString
). As PEP 675 advises for runtime type-checkers, @beartype now reduces (i.e., aliases) alltyping.LiteralString
type hints to the standardstr
type. Sadly, deeply type-checking literal strings is intractable for runtime type-checkers and is the textbook example of validation that can be performed only by static type-checkers. Type-checking literal strings requires:- Efficiently parsing abstract syntax trees (ASTs) at runtime (which is technically feasible, given sufficiently aggressive caching).
- Correctly transitively inferring literal strings across operations and calls (which requires parsing the entire codebase of the app stack and constructing an in-memory graph of all type relations, which is pragmatically
This isn't to say that PEP 675 is bad, however. PEP 675 is actually incredible, reducing the attack surface of database injection attacks at static analysis time with no harmful tradeoffs. And... who knows? With enough intestinal fortitude, handlebar mustaches, and monocled eyepieces, perhaps even @beartype can surmount this Hill of Thorns. Eventually. Maybe. But probably not.
Compatibility Improved
- PyPy. This release resolves a significant incompatibility with PyPy, whose implementation of the
id()
builtin appears to occasionally [read: non-deterministically] return object identifiers that are negative integers. Specifically, @beartype now guaranteeably generates valid parameter names passed to type-checking wrapper functions regardless of the sign of theid()
of the values of those parameters. Doing so resolves issue #232 kindly submitted by @jvesely (Jan Vesely) who purportedly lives in or around an ancient pork by-product that has calcified into stone -- which is quite impressive, really. Stoneham: it's like Stonehenge, only American and yummy in your tummy. Thanks so much for the heads up, @jvesely.
Errors Improved
- Readable violation messages. This release improves the readability of type-checking violation messages raised by @beartype, en-route to resolving feature request #216 kindly submitted by @felixchenier (AKA, le maître québécois en assurance qualité). Specifically, @beartype now prefixes type-checking violation messages with a terse description of the responsible callable (e.g.,
"Function"
,"Coroutine factory method"
) rather than the meaningless prefix"@beartyped"
. Explicitly detected types of callables include:- Coroutine factory functions, instance methods, and class methods.
- Asynchronous generator factory functions, instance methods, and class methods.
- Synchronous generator factory functions, instance methods, and class methods.
- "Normal" synchronous functions, instance methods, and class methods.
Tests Improved
- Module detection. This release dramatically simplifies the private
beartype._util.mod.utilmodtest.is_module_version_at_least()
tester to cease deferring to the fragile third-partypkg_resources
package -- which now emitsDeprecationWarning
warnings implicitly coerced by pytest into test failures. Begone, foulpkg_resources
!
API Changed
- Added:
- A new public PEP 673-specific
beartype.roar.BeartypeDecorHintPep673Exception
exception subclass.
- A new public PEP 673-specific
(Plucky puppies in a saggy rucksack!)