Beartype 0.22.0 Release Candidate 0: "Yo Dawg We Heard You Like LLM" Edition #551
Replies: 5 comments 11 replies
-
|
Works here: |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @leycec ! This appears to work on one of my tools at least. I was hoping that the note on What I want to achieve is beartype type checking for Code (written but not tested): # tests/test_something.py
import pytest
@pytest.fixture
def my_fixture() -> int:
pass
def test_foo(my_fixture: str) -> None: # `my_fixture` should be `int`, not `str`
passI then run Please let me know if you would like a small reproducer / separate issue. |
Beta Was this translation helpful? Give feedback.
-
|
Amazing work, as always. :) All tests for Plum pass for |
Beta Was this translation helpful? Give feedback.
-
|
UPDATE: As a bonus addendum, I neglected to mention in my desperate struggle for sleep last night that @beartype PEP 646 is outrageously huge. It's the longest and cruelest Type Variable Tuples: They're Weird and Kinda Suck, But Maybe Somebody Who Is a Good Person Loves ThemPEP 646 introduces type variable tuples (i.e., 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., 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
Tuple Type Hint Unpacking: They're Also Weird, But They're Actually Useful!?PEP 646 also introduces tuple type hint unpacking (e.g.,
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:
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
@beartype
|
Beta Was this translation helpful? Give feedback.
-
|
Awesome update! I don't have any tests complaining in my |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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.0rc0is LLM compatibility. Do you like LLM? Do you like compatibility? Then your code likes @beartype0.22.0rc0(even against your better judgement). But before the liking starts...@beartype
0.22.0rc0salutes 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.
!!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.0rc0today: 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.0rc0dramatically 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.0rc0weeps 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.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.0rc0now 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.0rc0now 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!?
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?
Beta Was this translation helpful? Give feedback.
All reactions