Beartype 0.22.0: Yo Dawg We Heard You Like LLM #559
Replies: 6 comments 5 replies
-
|
...lol. Woops. I accidentally hit |
Beta Was this translation helpful? Give feedback.
-
|
It's up! By Gods, it's up. It also accidentally got bumped to |
Beta Was this translation helpful? Give feedback.
-
|
...heh. Looks like we're on |
Beta Was this translation helpful? Give feedback.
-
|
@beartype # Via "pip", the once-great venerable master packager now fallen on hard times:
$ pip install --upgrade beartype # <-- you go, old man pip
# Via "uv", the plucky upstart spiky-haired kid wielding a sword larger than its body:
$ uv lock --upgrade-package beartype # <-- you are cleared for takeoffThat's right.
@beartype GitHub Sponsors: Befriend the Bear and Get a Bear for LifeThis release comes courtesy these proud GitHub Sponsors, without whom everyone in the @leycec family would currently be eating grasshoppers in the abandoned back lot again:
If you represent a security-conscious corporate, government, or non-profit, the best way bar none for you to support @beartype and secure your own workflow is by subscribing to Tidelift through SonarQube Advanced Security. Security giant Sonar recently acquired Tidelift, guaranteeing the economic viability of the Tidelift model for billions of future open-source projects that have yet to be born. Join the jargon-laden conversation and pay someone else to think about unreadable acronyms like SAST, SCA, and SBOM for once. Thanks so much, masters of fintech and lifted tides.
Patch Release? What's This All About Then?@beartype
Lastly but Beastly (but not Leastly)......to financially feed @leycec and his friendly @beartype through either:
Cue hypnagogic rave music that encourages fiscal irresponsibility. 🎵 🎹 🎶 Bear Club: The First Rule of Bear Club Is You Crush Bugs@beartype high-fives the reclusive secret society of worldwide bear bros who might possibly care about this. You are the select few. The elect enlightened. You are:
|
Beta Was this translation helpful? Give feedback.
-
|
@beartype # Via "pip", the once-great venerable master packager now fallen on hard times:
$ pip install --upgrade beartype # <-- you go, pipe-smoking pip
# Via "uv", the plucky upstart spiky-haired kid wielding a sword larger than its body:
$ uv lock --upgrade-package beartype # <-- you do what you need to do, ultraviolet radiation@beartype
@beartype GitHub Sponsors: Befriend the Bear and Get a Bear for LifeThis release comes courtesy these proud GitHub Sponsors, without whom everyone in the @leycec family would currently be eating grasshoppers in the abandoned back lot again:
If you represent a security-conscious corporate, government, or non-profit, the best way bar none for you to support @beartype and secure your own workflow is by subscribing to Tidelift through SonarQube Advanced Security. Security giant Sonar recently acquired Tidelift, guaranteeing the economic viability of the Tidelift model for billions of future open-source projects that have yet to be born. Join the jargon-laden conversation and pay someone else to think about unreadable acronyms like SAST, SCA, and SBOM for once. Thanks so much, masters of fintech and lifted tides.
Gods Not Another Patch Release. What's Wrong with You, @beartype?@beartype Everything. @beartype requires-python = ">=3.10,!=3.14rc1,!=3.14rc2"That syntax is valid. But Poetry and @beartype
Lastly but Beastly (but not Leastly)......to financially feed @leycec and his friendly @beartype through either:
Cue hypnagogic rave music that encourages fiscal irresponsibility. 🎵 🎹 🎶 Bear Club: The First Rule of Bear Club Is You Crush Bugs@beartype high-fives the reclusive secret society of worldwide bear bros who might possibly care about this. You are the select few. The elect enlightened. You are: @nizdolin, @SaiAakash, @markspace, @Spikhalskiy! Because you care, @beartype cares.
|
Beta Was this translation helpful? Give feedback.
-
|
@beartype @beartype # Via "pip", the once-great venerable master packager now fallen on hard times:
$ pip install --upgrade beartype # <-- you go, pipe-smoking pip
# Via "uv", the plucky upstart spiky-haired kid wielding a sword larger than its body:
$ uv lock --upgrade-package beartype # <-- you do what you need to do, ultraviolet radiation@beartype
@beartype GitHub Sponsors: Befriend the Bear and Get a Bear for LifeThis release comes courtesy these proud GitHub Sponsors, without whom everyone in the @leycec family would currently be eating grasshoppers in the abandoned back lot again:
If you represent a security-conscious corporate, government, or non-profit, the best way bar none for you to support @beartype and secure your own workflow is by subscribing to Tidelift through SonarQube Advanced Security. Security giant Sonar recently acquired Tidelift, guaranteeing the economic viability of the Tidelift model for billions of future open-source projects that have yet to be born. Join the jargon-laden conversation and pay someone else to think about unreadable acronyms like SAST, SCA, and SBOM for once. Thanks so much, masters of fintech and lifted tides.
Gods Not Another Patch Release. What's Still Wrong with You, @beartype?@beartype
FastMCP users really care about Python optimization. Apparently, nobody else does. Makes sense. Even @beartype is too slow for those speed-obsessed LLM gurus. How can this be!? It's never enough for the AI. In the relentless drive for faster query turnaround times, FastMCP is plumbing the depths of the impossible. There are always casualties on the road to progress. @beartype was one of those casualties. But no more. @beartype @beartype +
Lastly but Beastly (but not Leastly)......to financially feed @leycec and his friendly @beartype through either:
Cue hypnagogic rave music that encourages fiscal irresponsibility. 🎵 🎹 🎶 Bear Club: The First Rule of Bear Club Is You Crush Bugs@beartype high-fives the reclusive secret society of worldwide bear bros who might possibly care about this. You are the select few. The elect enlightened. You are: @strawgate. @Glinte. @bitranox. Heroes among us.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beartype
0.22.00.22.10.22.2 portals into the mortal plenum with a disturbing "WHOOOMP!" As you panic, all the oxygen in the room is rapidly vacuumed into an adjacent hyperdimension. It's not @beartype's safest entrance – but it's one we're all sure to remember. This is @beartype0.22.2: don't ask what happened to0.22.0. just... don't.pip install --upgrade --pre beartype # beartype casts magic missile on the darknessThe central dogma of @beartype
0.22.2is LLM compatibility. Do you like LLM? Do you like compatibility? Then your code likes @beartype0.22.2(even against your better judgement). But before the liking starts...@beartype
0.22.2salutes you who are about to code@leycec and his beautiful science wife are eating well. Thanks entirely to...
GitHub Sponsors: Befriend the Bear and Get a Bear for Life
This release comes courtesy these proud GitHub Sponsors, without whom @leycec's cats would currently be eating grasshoppers in the abandoned back lot again:
https://sescollc.com
https://dylanmodesitt.com
Additional financial shout-outs to @ilyapoz (@Ilia Pozhilov), the amazing former Yandex code cosmonaut who graciously donated a pile of Georgian lari to @beartype this go-around. Apparently, the lari is denominated in the ლ Unicode character. What a symbol! It looks like a beautiful hat. If only the Canadian dollar was half as manly. 😭
Thanks so much, masters of fintech and Yandex.
The Masters of Fintech and Yandex. That's who.
Tidelift: A Rising Tide Lifted @beartype's Not-At-All-Leaky Boat
This release also comes courtesy Tidelift, which very graciously pays out recurring income to security-sensitive open-source projects like @beartype, NumPy, and other stuff you probably care about. @beartype joining Tidelift has super-positive implications for Python's broader QA community – including:
responsibilityQA. Somebody smart said that.If you represent a security-conscious corporate, government, or non-profit, the best way bar none for you to support @beartype and secure your own workflow is by subscribing to Tidelift through SonarQube Advanced Security. Security giant Sonar recently acquired Tidelift, guaranteeing the economic viability of the Tidelift model for billions of future open-source projects that have yet to be born. Join the jargon-laden conversation and pay someone else to think about unreadable acronyms like SAST, SCA, and SBOM for once.
Pictured: Artistic rendition of the @beartype development process before Tidelift. You weren't supposed to see this.
!!STUFF YOU WANNA READ EVEN THOUGH ITS EXHAUSTING!!
You really want to bump the @beartype requirement in your
pyproject.tomlfile. Preserve end user sanity tomorrow by explicitly requiring a minimum of @beartype>=0.22.2today: e.g.,Why? Bear with us. This explanation may bore you. Imagine what typing this out felt like.
Prior versions of @beartype are fundamentally incompatible with Python 3.14. Python packagers like
pipanduvdo not update packages by default. Unless you bump your @beartype requirement, your existing userbase who already installed your package will be unable to use your package under Python 3.14 – even after manually updating your package, because manually updating your package fails to transitively update all dependencies of your package by default. In other words, Python packaging still kinda sucks.This is why...
@beartype looks stoically into the wind as everything breaks
!!MORE STUFF YOU WANNA READ EVEN THOUGH ITS EXHAUSTING!!
beartype.clawimport hooks have been supremely revamped. They still work the same, but they're now explicitly compatible with a lot more than they used to be. If you tried enablingbeartype_this_package()but switched back to manually decorating everything with@beartypebecausebeartype_this_package()spewed too many errors everywhere, please givebeartype_this_package()a second chance:Let us know how it goes. If stuff is still busted, we'll immediately fix that stuff. We now have the necessary machinery in our abstract syntax tree (AST) transformer to support all (or most, anyway) compatibility woes previously associated with
beartype.clawimport hooks.the new
beartype.clawshamelessly dances for anyonetl;dr: Llamas, Bears, & You
@beartype
0.22.2dramatically improves compatibility across the board with the APIs, packages, and paradigms you care about. Because you care, we care. In fact, we spent whole months caring. We cared so much we're all cared out. The summer went away in a blitz of caring and we didn't even notice. Oh, Gods. The warmth has fled. The snow is coming. And all we have to show for it is massive compatibility gains across the board.This includes:
@beartype
0.22.2weeps from pride and accomplishment, but mostly sleep deprivationPython 3.14: Oh, It's Big
Python 3.14. You care about Python 3.14 even if you don't know you care. @beartype now fully supports PEP 649 and 749 – landmark QA standards introduced by Python 3.14 that finally obsolete PEP 563. All these numbers mean something. We swear. Since all horror stories start with two nondescript teens in a Buick, let's start there:
That's PEP 563. And... that's now deprecated. PEP 749 officially deprecated PEP 563 a few months ago:
tl;dr: On October ~15th 2029,
from __future__ import annotationswill be officially deprecated. On October ~15th 2031,from __future__ import annotationswill be removed entirely from the Python language. At that time, any module usingfrom __future__ import annotationswill raise aSyntaxErrorat importation time and thus become unimportable. In 2025, nobody should enablefrom __future__ import annotationsvoluntarily.Sometime over the next several five years, you and your righteous dev team will require Python ≥ 3.14 as a mandatory dependency. That's just the way of the Python world. Planned obsolesce is the road we walk. When that happens, you'll no longer need
from __future__ import annotationsto declare forward references to undefined types in type hints like this:Unquoted forward references are thus baked into Python 3.14. Order of type hints and types is no longer significant. Define and annotate stuff in any order you like.
@beartype
0.22.2: because life is too short and code is too long.@beartype: always ready to rip its shirt off at the slightest provocation
Large Language Models: Apparently, They're Large
@beartype
0.22.2now ships with out-of-the-box support for Bad Boy LLM APIs that defy community standards, mental health, and your last hair follicles. This includes:These APIs are awesome, because they changed the world. But they're also hostile to literally every other Python decorator in existence. @beartype is a Python decorator in existence. Thus, these APIs are hostile to @beartype.
Why? Because they all define decorator-hostile decorators: that is, decorators that prevent other decorators from being applied. That's not how decorators are supposed to work. You're supposed to be able to apply decorators in any arbitrary order. That was the deal, LLM APIs! Apparently, LLM APIs hated that deal. Their decorators destructively transform your normal functions and methods (which are decoratable by @beartype) into abnormal instances of API-specific types (which are not decoratable by @beartype).
In the worst case of both LangChain and FastMCP, these abnormal instances of API-specific types aren't even callable! They don't just destroy the types of what they decorate. They destroy the callability of what they decorate. What kind of compatibility-hostile API turns a function or method into an uncallable object that you can't do anything with anymore? LangChain and FastMCP. That's who.
Examples include:
@langchain_core.runnables.chaindecorator function.@fastmcp.FastMCP.tooldecorator method.@celery.Celery.taskdecorator method.@beartype
0.22.2now officially supports decorator-hostile decorators like this. It cost us our summer, but no price is too high. Okay. The price was pretty high. But this is the AI-ML-LLM hype train we're talking about. You either board that train or you prepare to eat everybody else's dust as they point fingers and cruelly guffaw into their monocles at you. @beartype prefers to board that train.@beartype walks its own road, though. @beartype boards that train in its own special way. Specifically, @beartype now maintains two internal databases efficiently structured as trie prefix search trees:
beartype.clawimport hooks then:@beartypedecorator before (rather than after) the last decorator-hostile decorator in existing chains of two or more consecutive decorators decorating your callables and types in your modules.@beartypedecorator now silently ignores attempts to decorate instances of these problematic types. Don't even bother! They're busted, @beartype. At least we no longer are. 😅It's... complicated. Really, really complicated. There's a doctoral PhD thesis somewhere here for somebody who wants one. Me? I just wanna sleep. Blessed sleep! Take me now!
left: @beartype. right: langchain, fastmcp, and celery. you think we forgive you that easily!?
Polars: Cold as Ice, DataFrames Are Nice
Polars is the vibrant Pandas alternative everyone loves. 35k GitHub stars cannot be wrong. Although I feel jealousy when I hear numbers like that, @beartype now officially supports validation of Polars DataFrames vis-a-vis Pandera – the only sane way to validate the integrity of your fragile DataFrames that are probably falling over as we speak. Poor guys.
Previously, @beartype only supported validation of Pandas DataFrames via Pandera. Now, @beartype supports both Pandas and Polars. This can only mean one thing. Our powers are growing at an exponential rate. The QA Singularity is upon us. Check out this terrifying exhibition of runtime validation run amok:
...which helpfully blows up with a human-readable exception that relieves you:
@beartype: Bleeding-edge APIs named after magnetic dipoles? Yeah. We do that, too.
@beartype
0.22.2pours one out for the DataFrame that didn't make it.PEP 646: We Don't Understand Variadic Generics Either, But Apparently @beartype Now Supports Them
@beartype
0.22.2fully supports PEP 646 – Variadic Generics. ...for certain glib definitions of "fully supports."PEP 646 is outrageously huge. It's the longest and cruelest
typingstandard published to date. Synopsizing that standard is a fool's errand. Thus, we now synopsize that standard. PEP 646 brings two things to the QA table. Let's go!I-I-Is that @beartype's arm she's holding up!? 😮
Type Variable Tuples: They're Weird and Kinda Suck, But Maybe Somebody Who Is a Good Person Loves Them
PEP 646 introduces type variable tuples (i.e.,
typing.TypeVarTuple(...)objects). Whereas good ol' PEP 484-compliant type variables (i.e.,typing.TypeVar(...)objects) match only a single type (likeMuhGeneric[int]forclass MuhGeneric[T](): ...), type variable tuples greedily match zero or more types (likeWoahGeneric[int, str, bool]forclass WoahGeneric[*Ts](): ...).The use case is tensors, supposedly. I personally press "F" to doubt that any real-world tensor frameworks will actually leverage type variable tuples. Doing so would inhibit forward compatibility with future tensor APIs in those frameworks. Why? Because type variable tuples match types greedily. Once you've exposed a type variable tuple to your end users through a public-facing generic type, you can never add any other type variables to that generic type without breaking backward compatibility. You're now permanently locked in to that generic type API for the rest of all time.
Aren't ordinary type variables like that too, though? No. You can always add additional type variables to normal generic types without breaking backward compatibility. How? PEP 696-compliant type variable defaults (e.g.,
T = TypeVar("T", default=int)). Press "F" if anyone would like me to babble incoherently more about all this.That said, type variable tuples probably do have practical internal use. I'd never expose them to end users for the aforementioned reasons. They cause compatibility woes. Still, @beartype
0.22.2now fully supports them. Use them! Reassure us that we didn't waste the entire summer on this! Oh, Gods... the summer... it's... it's gone, everybody. 😩@beartype
0.22.2when it realized where the summer wentTuple Type Hint Unpacking: They're Also Weird, But They're Actually Useful!?
PEP 646 also introduces tuple type hint unpacking (e.g.,
tuple[int, *tuple[str, ...]]). This spec goes really hard really fast. The syntax is also kinda nasty. But the core idea is that you can now deeply type-check the contents of non-trivial tuple data structures. You may now be thinking:Indeed! It's all true! You can use tuples like data structures. @beartype internally does this all the time. Why? Unjustifiable microoptimizations. Because CPython is highly internally optimized for tuple instantiation, access, and garbage-collection, tuples make the ideal read-only data structures for many perfidious purposes. CPython cares a lot about tuples. Tuples are the backbone of CPython's calling convention, because functions and methods returning multiple values implicitly return tuples of those values. This makes tuples the ideal data structures for implementing many pure-Python algorithms – especially recursive algorithms implemented iteratively.
Of course, tuple data structures do promote unreadable and obfuscated code that not even the unpaid intern wants to maintain. But that's not a problem if you're a dodgy codebase like @beartype. Ain't nobody maintaining this code except @leycec – a well-known glutton for punishment-by-dev-hell.
If you are like @leycec, you too can now type-check your shamefully growing heap of tuple data structures from Hell. How? PEP 646, yo. Previously, PEP 484 only let you type-check two simplistic kinds of tuple hints:
tuple[str, int], for example, is the fixed tuple hint matching tuples containing one string item followed by an integer item.tuple[str, ...], for example, is the variadic tuple hint matching tuples containing zero or more string items.That's great if your tuple data structures are simplistic. But they're probably not, are they? That's why you're still reading this at 4:17AM. Your wife is calling out for you in her fitful sleep, but you don't even care! This is riveting Internet reading right here!
So what if your tuple data structures are as complicated as your marriage? You reach for PEP 646 and @beartype
0.22.2. You can now unpack at most one child tuple hint inside another parent tuple hint. For reasons that will become clear shortly, most child tuple hints unpacked in this way are variadic. Do that and you've now defined a mixed fixed-variadic tuple hint that matches tuples containing (in order):tuple[str, bytes, *tuple[int, ...], bool, float], for example, is the mixed fixed-variadic tuple hint matching tuples containing (in order) a string item, a byte string item, zero or more integer items, a boolean item, and a floating-point number item. Cool, right? But the coolness doesn't stop there. Consider cardinality. Old-school variadic tuple hints (liketuple[str, ...]) only match tuples containing zero or more items. But what if you want to match a positive number of items? Tuple hint unpacking trivially lets you do that, too.tuple[str, *tuple[str, ...]], for example, is the mixed fixed-variadic tuple hint matching tuples containing one or more strings. This example then generalizes to arbitrary cardinality bound only by your patience and openness to syntactic barbarism. Want to match tuples containing a larger number of strings? Just keep prependingstrchild type hints until you're satisfied, exhausted, and dripping with sweat at 4:17AM.tuple[str, str, str, str, str, *tuple[str, ...]], for example, is the mixed fixed-variadic tuple hint matching tuples containing five or more strings. It's silly. Yet, it works. Kinda.@beartype
0.22.2: it's only silly if you admit it's silly.beartype
0.22.2proudly unpacks tuple hints as the wind blows its hair aroundLastly but Beastly (but not Leastly)...
...to financially feed @leycec and his friendly @beartype through either:
Cue hypnagogic rave music that encourages fiscal irresponsibility. 🎵 🎹 🎶
Bear Club: The First Rule of Bear Club Is You Crush Bugs
@beartype high-fives the reclusive secret society of worldwide bear bros who might possibly care about this. You are the select few. The elect enlightened. You are:
@posita, @wesselb, @tusharsadhwani, @JWCS, @patrick-kidger, @EtaoinWu, @iamrecursion, @Moosems, @langfield, @sylvorg, @Glinte, @cclauss, @sean-roelofs-ai, @kultura-luke, @jonathanberthias, @gotmax23, @adamtheturtle, @ilyapoz, @MilesCranmer, @rg936672, @ddorian, @k4ml, @riesentoaster, @LeonHilf, @jeertmans, @mzealey, @thetianshuhuang, @RomainBrault, @alisaifee, @ArneBachmannDLR, @JelleZijlstra, @tactile-metrology, @RobPasMue, @GithubCamouflaged, @kloczek, @uriyasama, @danielgafni, @JWCS, @rbroderi, @AlanCoding, @tvdboom, @crypdick, @jvesely, @komodovaran, @kaparoo, @MaximilienLC, @fleimgruber, @alexoshin, @gabrieldemarmiesse, @James4Ever0, @NLPShenanigans, @rtbs-dev, @yurivict, @st--, @murphyk, @dosisod, @Rogdham, @alisaifee, @denisrosset, @damarro3, @ruancomelli, @jondequinor, @harshita-gupta, @jakebailey, @denballakh, @jaanli, @creatorrr, @msvensson222, @avolchek, @femtomc, @AdrienPensart, @jakelongo, @Artur-Galstyan, @ArneBachmann, @danielward27, @WeepingClown13, @rbnhd, @radomirgr, @rwiegan, @brettc, @spagdoon0411, @helderco, @paulwouters, @jamesbraza, @dcharatan, @kasium, @AdrienPensart, @sunildkumar, @peske, @mentalisttraceur, @awf, @PhilipVinc, @dcharatan, @empyrealapp, @rlkelly, @KyleKing, @skeggse, @RomainBrault, @deepyaman, @minmax, @jedie, @pablovela5620, @thiswillbeyourgithub, @Logan-Pageler, @knyazer, @ilyapoz, @yuzhichang, @Fedezzab, @antonioan, @im-Kitsch, @mthramann, @fbartolic, @rgallardone, @frrad, @jonnyhyman, @jennydaman, @likewei92, @acec2127, @rudimichal, @woutdenolf, @PauloHMTeixeira.
left: @beartype. right: you. why is it always like this?
Beta Was this translation helpful? Give feedback.
All reactions