Beartype 0.22.0 Release Candidate 0 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 @beartype 0.22.0rc0:
pip install --upgrade --pre beartype # beartype casts magic missile on the darknessThe central dogma of @beartype 0.22.0rc0 is LLM compatibility. Do you like LLM? Do you like compatibility? Then your code likes @beartype 0.22.0rc0 (even against your better judgement). But before the liking starts...
@beartype 0.22.0rc0 salutes 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:
- @sesco-llc (SESCO Enterprises), "The Power of Innovation in Trading": this inspires me to get out of the house and do something
https://sescollc.com - @DylanModesitt (Dylan Modesitt), quantitative strategies energy trading associate: ...wikipedia, don't fail me now!
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.
!!STUFF YOU WANNA READ EVEN THOUGH ITS EXHAUSTING!!
You really want to bump the @beartype requirement in your pyproject.toml file. Preserve end user sanity tomorrow by explicitly requiring a minimum of @beartype >=0.22.0rc0 today: e.g.,
# In your top-level "pyproject.toml" configuration:
dependencies = [
...
"beartype >=0.22.0rc0", # <-- once you go 0.22.0, you go 0.22.0 for life
...
]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 pip and uv do 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.claw import 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 enabling beartype_this_package() but switched back to manually decorating everything with @beartype because beartype_this_package() spewed too many errors everywhere, please give beartype_this_package() a second chance:
# In the "{your_package}.__init__" submodule:
from beartype.claw import beartype_this_package
beartype_this_package() # <-- we're willing to swear on our pinkies that this works nowLet 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.claw import hooks.
the new beartype.claw shamelessly dances for anyone
tl;dr: Llamas, Bears, & You
@beartype 0.22.0rc0 dramatically 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:
- Python 3.14! 🐍
- LangChain! ⛓️
- FastMCP! 💨
- Celery! 🥗
@beartype 0.22.0rc0 weeps from pride and accomplishment, but mostly sleep deprivation
Python 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:
from __future__ import annotationsThat's PEP 563. And... that's now deprecated. PEP 749 officially deprecated PEP 563 a few months ago:
Sometime after the last release that did not support PEP 649 semantics (expected to be 3.13) reaches its end-of-life,
from __future__ import annotationsis deprecated. Compiling any code that uses the future import will emit a DeprecationWarning. This will happen no sooner than the first release after Python 3.13 reaches its end-of-life, but the community may decide to wait longer.
After at least two releases, the future import is removed, and annotations are always evaluated as per PEP 649. Code that continues to use the future import will raise aSyntaxError, similar to any other undefined future import.
tl;dr: On October ~15th 2029, from __future__ import annotations will be officially deprecated. On October ~15th 2031, from __future__ import annotations will be removed entirely from the Python language. At that time, any module using from __future__ import annotations will raise a SyntaxError at importation time and thus become unimportable. In 2025, nobody should enable from __future__ import annotations voluntarily.
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 annotations to declare forward references to undefined types in type hints like this:
# Look, Ma! No "from __future__ import annotations".
# We don't need the future where we're going.
from beartype import beartype
# Under Python ≥ 3.14, this just works. You annotated a function as accepting
# an instance of a type you haven't even declared yet. Yet, this is now fine.
# @beartype accepts you and your suspicious code for you who are.
@beartype
def useless_func(forward_reference_to_undefined_type: ThisJustWorksNow) -> ThisJustWorksNow:
return forward_reference_to_undefined_type
# Of course, you *DO* have to eventually define the undefined type used above.
# If you don't, everything will still blow up. It's not @beartype's fault.
# Python 3.14 made us do it... We blame Guido.
class ThisJustWorksNow(object):
passUnquoted 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.0rc0: 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.0rc0 now 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:
- LangChain, the 500lb gorilla of the LLM space. We all know it. Some of us shake our fist at it. Many of us prostrate ourselves before it in mute supplication. But all of us must admit... LangChain changed the world. Even if everybody now tries to pretend that only LangGraph exists, LangChain still exists underneath it all – lurking in the grimy shadows with a sinister leer plastered across its placid facade. 🧟
- FastMCP, the LangChain of the Model Context Protocol (MCP) world. None of this makes sense. Even I no longer know what I'm talking about. Just pretend you too know what the increasingly nonsensical alphabet soup of AI-ML-LLM hype train jargon means. Everyone, let us fake it until our resume says we make it. 🚆
- Celery. Yeah, yeah. Technically, Celery is larger than AI life. It's the Pythonic task queue on massively parallelized compute nodes. Pragmatically, though, even Celery has rapidly pivoted its previously Django-centric worldview towards the sweeter and more fulfilling world of AI hype. I just wish they'd chosen a more delicious vegetable as their nom de plume. I mean... celery? That stuff's disgusting – and I'm a vegan, sometimes occasionally even by choice. 🥗
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:
- The
@langchain_core.runnables.chaindecorator function. - The
@fastmcp.FastMCP.tooldecorator method. - The
@celery.Celery.taskdecorator method.
@beartype 0.22.0rc0 now 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:
- The decorator beforelist. The beforelist is @beartype's first line of LLM defense. It's an internal database of the names of all third-party packages, modules, and types transitively defining one or more decorator-hostile decorators.
beartype.clawimport hooks then:- Track both your importation of these problematic attributes and your instantiation of these problematic types into your modules.
- Inject the
@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.
- The decorator blacklist. The blacklist is @beartype's last line of LLM defense. It's an internal database of the names of all third-party types produced by decorator-hostile decorators in the beforelist. The
@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!?
Lastly but Beastly (but not Leastly)...
...to financially feed @leycec and his friendly @beartype through our ancient GitHub Sponsors profile that predates the existence of dinosaur-like AI chatbots. Come for the candid insider photos of a sordid and disreputable life in the Canadian interior; stay for the GitHub badge and warm feelings of general goodwill.
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, and @k4ml.
left: @beartype. right: you. why is it always like this?
