PEP 563 (i.e., from __future__ import annotations) Is Deprecated: "Ding Dong, the Witchy PEP Is Dead."
#299
Replies: 4 comments
-
I'm highly skeptical that the Python Core Developers will break backwards compatibility "just like that". And at the very least, the either-or in this can be clarified: it is against policy for an object located in The new approach to annotations is supposed to be more or less backwards compatible. The details are discussed at https://peps.python.org/pep-0649/#backwards-compatibility-with-pep-563-semantics
Do you have a citation for that? Because it really should not be creating code objects -- it is documented to not do so -- so if it were really being inefficient like that then that would be a CPython 3.7 - 3.12 bug and I'd have expected someone to report it by now (possibly you). |
Beta Was this translation helpful? Give feedback.
-
I'm unsure how you formed this conclusion. It is totally unrelated to forward annotations. The new
The recourse is to simply not change anything, which continues to do precisely what it always did on python < 3.12 -- and also for that matter python 3.12 itself. It will either continue to do what it used to do, or simply do nothing and leave you with PEP 649 deferred annotations by default on versions of python that dropped all support for PEP 563 but do support 649. One could of course argue that explicit is better than implicit, but this is dogma, not an implementation requirement. |
Beta Was this translation helpful? Give feedback.
-
No one is breaking backwards compatibility "just like that." Not even @beartype does that – and we play fast and loose around here. This is how it works:
That's how deprecations work. That's what deprecations mean. You get a warning that backward compatibility will be broken. Then you get the error, which is backward compatibility being broken. PEP 649 has warned you that PEP 563 has been officially deprecated. You are, of course, free to ignore that deprecation. Ignoring deprecations is obviously unwise. Nonetheless, freedom means the freedom to faceplant into the yawning cliff that is now looming in front you. I exercise that freedom by avoiding the cliff. But you do you, you know? I'm not here to argue with reality, @eli-schwartz. I'm here to describe reality. It's what I do. It's an Aspy thing.
They should break the import. They're breaking backward compatibility. So, they should explicitly inform everyone they're breaking your code by removing That said... I don't particularly care. I'm unaffected either way. I never used
Bro, it's not. You seem really argumentative. Why are you really argumentative? PEP 649 explicitly told you that PEP 563 is now officially deprecated. The new approach to annotations thus fundamentally breaks backwards compatibility with
Wow. So we have confirmed you are here to argue. Kinda disappointed, to be honest. Flame wars are strictly verboten here. We all got better things to do. Likewise, nobody said nuffin' about "creating code objects." But... thanks for putting words in my digital mouth that hopefully has less broken teeth than my physical mouth, I guess? I said that "PEP 563 forces the Python interpreter to parse every type hint from a string into an abstract syntax tree (AST) node and then unparse that same node back into a string," which is exactly what Python does when you enable PEP 563 via Seriously. Python parses and then unparses itself under PEP 563. That's well-known. That's how it works. That's well-documented everywhere. See also Python's official developer handbook:
How did you think any of that crusty black magic worked, anyway? Actually, belay that question. I increasingly don't want to know – because you are here to argue about everything. It saddens us all.
Seriously. Do you really have any idea what you are talking about or do you just spout random inanities as if that makes them true? PEP 695-compliant # A type alias that includes a forward reference
type AnimalOrVegetable = Animal | "Vegetable"Verily, and I yet again quote PEP 695:
Do you know what "evaluated lazily" means here? It means that the value of the type alias created by a
What do you think a "reference to a name that is not yet defined" is? That's right. It's a forward reference. If you want an unquoted forward reference in Python ≥ 3.12 without exposing yourself to deprecations, you have to use PEP 695. There is no other way. PEP 563 is officially deprecated. Can we please move on? Arguing with reality isn't a good look. Please at least read the PEP you are arguing about before arguing about that PEP. I sigh with XML yet again.
Code that contains implicit forward references (i.e., type hints referencing undeclared objects under This means code like this: from __future__ import annotations
def muh_func() -> MuhClass: pass # <-- dis about to break, yo
class MuhClass(object): passThat will break. "Simply not changing anything" is not an option. Do nothing and all code with implicit forward references will die. Ignore the deprecation of PEP 563 and all code with implicit forward references will die. This is a hard-and-fast guarantee. Ignoring a bad thing coming does not prevent that bad thing from coming. Trainwreck emoji, I summon thee to save @eli-schwartz from himself! 🚋 💣 💥 |
Beta Was this translation helpful? Give feedback.
-
|
Wait. I get it. I get what you are saying, @eli-schwartz – and you're absolutely right about PEP 649 preserving backward compatibility in the way that matters most. I was blinded by a growing sense of futility and incoherent frustration at your argumentative communication style, which could really use some work. Seriously. Please meditate. But... you're almost certainly right about this: from __future__ import annotations
def muh_func() -> MuhClass: pass
class MuhClass(object): passThat will always work – even after support for PEP 563 is officially removed. How? Because, exactly as you suggest:
Gotcha. That makes total sense. That is actually fairly clever. And that is really the way it absolutely must be for sanity to prevail across the Python ecosystem, right? Right. I'll amend my original post to admit that doing absolutely nothing is both permissible and advisable for codebases that have already committed to PEP 563. Phew. You dodged a gruesome bullet there, PyTorch. We can all breath easily now. AI has been preserved! 🤖 |
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.
-
Spooky Halloween update intensifies. This is an official message of the Beartype Broadcasting Service. Trust no other.
Long has @leycec warned ye of the ill tidings of PEP 563, the standard previously known as
from __future__ import annotations. Yet long have ye ignored @leycec.Verily, for did @leycec not counsel all the corporations and academic institutions of the land that some future version of Python to come would deprecate PEP 563 and therefore thy entire fragile house of codebase cards built on the leaning back of PEP 563? Verily, that ill-fated day of fetid sorrow has come. Shudder as one, ye who reap what ye have sown!
</cackles>Yay. For @leycec quoths the ravenous PEP 649: "Nevermore."
Guess ye what? That PEP was accepted.
Can We Pretend It's Not Halloween for One Hot Minute?
Fine, fine. You're not wrong. Even I got tired of playing the biblical PEP prophet Leycecjah there. 😅
Here's the skinny: ...spooky idioms, thy name is English Language
from __future__ import annotationsunconditionally enables PEP 563.from __future__ import annotationsis officially deprecated and will be eventually removed or...from __future__ import annotationsthat specifically pertains to PEP 563 is officially deprecated and will be eventually removed.It's unclear which of these is the case. What is clear is that
from __future__ import annotationsis now a volatile and highly explosive compound.EDIT: The following paragraph is all lies and best ignored. Still, it made me chuckle quietly and I miss it already.
Regardless of whetherfrom __future__ import annotationsis going away in entirety or merely in part, backward compatibility will be broken. Something you currently rely upon is about to go on an all-you-can-drink bender in Tokyo's infamous Kabukicho red light district. (Been there, done that, can't remember a thing.) If your codebase or a codebase you love is currently prefacing literally every Python module withfrom __future__ import annotations, that codebase is now primed to viciously explode under Python ≥ 3.13.Do the right thing today, tomorrow, or next year at the latest. Just say "Let's pretend this never happened" to
from __future__ import annotations. GitHubbers don't let GitHubbersfrom __future__ import annotations. Not even once.B-b-but You're Breakin' Mah Heart, Here!
@beartype feels your pain, but fails to sympathize. It's Halloween, after all. No sympathy for the devil.
Alright. Alright already! Although devilish, you may now be wondering: "But what are we supposed to do now?" You have two choices – both of which suck:
from __future__ import annotationsfor all of the voluminous reasons enumerated below, existing codebases like PyTorch that have already gone all-in onfrom __future__ import annotationsshould avoid breaking their own backs. Your code is fine and will continue to work as is in perpetuity, because Python devs are less dumber than we think. To wit, those voluminous reasons for avoidingfrom __future__ import annotationsin new codebases are:typesyntax everywhere.typeis the newtypingBad Boy. It's PEP 563, except it actually works. Why? Because PEP 695 explicitly limits the scope of PEP 563-style behaviour to just a single statement (rather than the entire friggin' module). That statement is the newtypesyntax. This is PEP 695. This istype:To Those Who Are About to Cry, @beartype Pities You
Relevant downstream consumers severely exposed to this deprecation include:
PyTorch. The Gods weep! @justinchuby, I regretfully summon you to inform you that a badness is on the horizon. I've grepped over 100 instances offrom __future__ import annotationsthroughout the PyTorch codebase. Unwinding that is not going to prove trivial. On the contrary, it's gonna be boring; it's gonna take forever; it's gonna cause premature balding. In short, it's gonna hurt. Let us all be suddenly thankful we are not the fall guy for that one....because that is now officially deprecated is what I am saying. Even if PEP 563 was still alive, however, enabling PEP 563 via
from __future__ import annotationswould still be the wrong thing to do. Why? Because PEP 563:...because that will never be deprecated. @leycec guarantees it. ← never say something like this 😬 🤯 💥
Beta Was this translation helpful? Give feedback.
All reactions