Beartype 0.18.3: For Justice, For Victory, For QA #370
leycec
announced in
Announcements
Replies: 3 comments
-
Great work! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I feel very called out by this release. I probably should. I should also probably make that tactile metrology URL do something. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey, I'm glad to be called out by this; the more python I read, the better. ... What has my life become... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Beartype 0.18.3 is the minor patch release that your careening codebase can no longer live without:
Actually... I lied. I know! I gotta stop doing that. But the sordid truth is that beartype 0.18.3 is mostly just for @iamrecursion and @sylvorg, who single-handedly reported more issues in a single week than the exploding size of @leycec's JRPG backlog. And we know how big that is, don't we? It's big. It's so big it wraps around like a self-sustaining Niven ringworld habitat at Lagrange point L1. Big-big.
Beartype 0.18.3 is for @iamrecursion and @sylvorg. May their usernames live forever in
git log
infamy. In this release, a few more bugs die.But first...
GitHub Sponsors: They Scratch the Bear's Back. Now, The Bear Scratches Back.
This release comes courtesy these proud GitHub Sponsors, without whom @leycec's cats would currently be eating grasshoppers:
https://sescollc.com
https://dylanmodesitt.com
https://metrolo.gy imagine if this domain actually worked. how cool would that be!?
Thanks so much, masters of fintech and metrology.
The Masters of Fintech and Metrology. That's who.
Type Variables Bound by Forward References: So This Is a Thing, Huh?
So. Funny story. Turns out you can bound PEP 484-compliant type variables (i.e.,
typing.TypeVar(...)
objects) with forward references specified as strings. Who knew? Everybody except @leycec. Nobody tells that guy nuthin'.Beartype 0.18.3 now explicitly supports type variables bound by forward references. These are type hints of the form:
Previously, @beartype only partially supported such variables due to @leycec failing to realize that such variables even existed and constituted a valid use case. This is why your codebase can't have good things. Now, @beartype fully supports
heinous abominationsvalid use cases like:hangin' with the bear homies in apocalyptic wasteland ain't no thang
beartype.vale.Is[...]
: Now It Supports Crazy StuffThe functional beartype validator factory
beartype.vale.Is[...]
is now subscriptable (indexable) by all manner of shambolic nightmares. Previously, you had to subscriptIs[...]
with low-level functions and methods. Now, you can subscriptIs[...]
with high-level callable objects like:Class-based callables (i.e., objects whose classes define the
__call__()
dunder method, rendering otherwise uncallable objects callable): e.g.,Partials (i.e., high-level
functools.partial(...)
callable objects wrapping low-level functions and methods): e.g.,Is this valuable? No idea. Let's pretend I did something useful tonight so I can sleep without self-recrimination.
...heh. your eyes are now bleeding
Triply-Redeclared Types: Just don't ask.
Beartype 0.18.3 now sports improved support we rhymin' like it's 2099 ova here for Jupyter Notebook cells. Do you like Jupyter? Do you like @beartype? Then you need beartype 0.18.3 now, because beartype 0.18.2 probably already broke everything without your informed consent. Woops.
Beartype 0.18.3 resolves inscrutable non-determinism (which is technically deterministic if you squint at it, but we don't talk about that) with respect to repeatedly redefined classes defining one or more methods annotated by one or more self-referential relative forward reference (i.e., referring to the class currently being defined). @beartype is now considerably more robust against non-determinism in Jupyter cells containing
@beartype
-decorated self-referential classes like:Flex those burly QA biceps, @beartype. Flex 'em.
things explode when you put @beartype back in the sheath
__class_getitem__ = classmethod(GenericAlias)
: We Do That Too, Whatever That IsSo. You want to refactor your heroic class that will truly shape the course of human history into a subscriptable type hint factory. You even know about the convenient but unreadable one-line idiom for casting this dark magic. Previously, @beartype refused to support your
bad habitsarcane knowledge. Now, @beartype understands and appreciates everything you're trying to do for humanity.Beartype 0.18.3 generalizes the
@beartype
decorator to support decoration of user-defined types that declare class methods by directly calling the builtin@classmethod
decorator as a function passed a C-based callable type (e.g.,classmethod(types.GenericAlias)
). Doing so enables@beartype
to support the standard idiom for user-defined subscriptable type hint factories under Python >= 3.9:the pancakes get me every time. srsly. what is with those pancakes?
Forward Reference Deprioritization: What Does This Even Mean!?
Beartype 0.18.3 deprioritizes @beartype-specific forward reference proxies (i.e., internal objects proxying external user-defined types that have yet to be defined) in type tuples passed as the second arguments to the
isinstance()
builtin, reducing the likelihood that type-checks involving forward references will raise unexpected exceptions. For example, consider this simple example:...which unexpectedly prints without blowing up:
@beartype type-checks that the default value of the optional
muh_arg
parameter of themuh_func()
function satisfies the type hint'UndefinedType' | None
– despite the fact that theUndefinedType
class is undefined! To do so, @beartype now internally reorders the types comprising this union:Nobody should ever depend upon this. Therefore, this is a delicious nothingburger – but a delicious nothingburger that could yield future delights in the event that we actually elect to try type-checking defaults at decoration time again. We're not, of course. That would be foolish and dangerous. We're absolutely going to do that again.
rub those cat cheeks! rub 'em!
PEP 563 + PEP 673 + dunder methods.
Beartype 0.18.3 resolves a subtle interaction between PEP 563 (i.e.,
from __future__ import annotations
), PEP 673 (i.e.,typing{_extension}.Self
), and common dunder methods like... uh,__add__()
, I guess. Let's pretend that's common.Beartype 0.18.3 ensures that the type stack encapsulating the current
@beartype
-decorated class is now preserved throughout the type-checking process for standard dunder methods annotated by one or more PEP 673-complianttyping{_extension}.Self
type hints that are stringified under PEP 563. For example, @beartype now transparently supports pernicious edge cases resembling:If you wanted this, you are literally @iamrecursion. Congrats.
you too will believe that @beartype 0.18.3 actually works
Ping 'Em All
Pinging @posita, @iamrecursion, @sylvorg, @tactile-metrology, @kalaspuff, @danielward27, @kloczek, @uriyasama, @danielgafni, @JWCS, @rbroderi, @AlanCoding, @tvdboom, @crypdick, @WeepingClown13, @RobPasMue, @rbnhd, @radomirgr, @rbroderi.
You are wanted on floor 13. Japanese buildings don't even have a floor 13. Surely nothing could go wrong by violating that fundamental.
those dance moves can mean only one thing... This was @beartype 0.18.3.
Beta Was this translation helpful? Give feedback.
All reactions