On Sat, 23 Apr 2022 at 12:50, Larry Hastings <la...@hastings.org> wrote: > > > On 4/22/22 19:17, Chris Angelico wrote: > > I'm unsure about the forward class. How is it different from subclassing an > ABC? > > They're just different objects. A subclass of an ABC is either itself > another abstract base class, which will never be instantiatable, or a > non-abstract class, which is immediately instantiatable. A forward-declared > class object is not currently instantiatable, and is not fully defined, but > will become fully defined and instantiatable after the matching "continue > class" statement. >
Ah okay, I think I had the idea that an ABC could demand certain methods, but I think I'm mismatching semantics when it comes to half-implementing something. Anyhow, it's a class, with some special features (notably that you can't instantiate it). > > What happens if you try to continue a non-forward class? > > From the proto-PEP: > > Executing a `continue class` statement with a class defined by the `class` > statement raises a `ValueError` exception. > > And also: > > It's expected that knowledgeable users will be able to trick Python into > executing `continue class` on the same class multiple times by interfering > with "dunder" attributes. The same tricks may also permit users to trick > Python into executing `continue class` on a class defined by the `class` > statement. This is undefined and unsupported behavior, but Python will not > prevent it. > Huh. I skimmed back and forth looking, and did a search, and didn't find that. My bad. 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? And if multiple continuations are permitted, there's really no difference between a forward class and a regular class. It'd be a "non-instantiable class", which is an aspect which can be removed by reopening the class, but otherwise it's just like any other class. ChrisA _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/AELFL53RTT2GXOZ6NA7BFEJUE2BH67UR/ Code of Conduct: http://python.org/psf/codeofconduct/