On Sat, 23 Apr 2022 at 15:32, Larry Hastings
On 4/22/22 22:03, Chris Angelico wrote:
Anyhow, [a forward-defined class object is] a class, with some special features (notably that you can't instantiate it).
Yes. Specifically, here's my intention for "forward-defined class objects": you can examine some generic dunder values (__name__, __mro__), and you can take references to it. You can't instantiate it or meaningfully examine its contents, because it hasn't been fully initialized yet.
It seems odd that you define a blessed way of monkeypatching a class, but then demand that it can only be done once unless you mess with dunders. Why not just allow multiple continuations?
I think monkeypatching is bad, and I'm trying to avoid Python condoning it.
On that note, the intent of my proposal is that "continue class" is not viewed as "monkeypatching" the class, it's the second step in defining the class.
I considered attempting to prevent the user modifying the "forward-declared class object". But a) that just seemed like an arms race with the user--"oh yeah? well watch THIS!" and b) I thought the Consenting Adults rule applied.
Still, it's not the intent of my PEP to condone or facilitate monkeypatching.
I guess perception is everything. This really *is* monkeypatching; you have an object, and that object will be mutated, and those mutations are defined by adding functionality to the class. It's not fundamentally different from X.__dict__.update() with a pile of new methods etc. The only difference is that you call it something different. Is that sufficient justification? I'm unsure. ChrisA