On Wed, 27 Apr 2022 at 16:04, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
>
> On 27/04/22 1:26 pm, Chris Angelico wrote:
> > On Wed, 27 Apr 2022 at 11:18, Greg Ewing <greg.ew...@canterbury.ac.nz> 
> > wrote:
> >>
> >> The proposed feature is analogous to forward declaring a
> >> struct in C. Would you call what C does monkeypatching?
> >>
> > No, because C doesn't have first-class types, much less mutable ones.
>
> The purpose of a forward declaration, in any language, is to
> allow a name to be used before it's fully defined. Mutability
> or first-classness of types has nothing to do with it.

The ONLY thing you can do in C without the full structure definition
is to declare a pointer to it. It has all the functionality of a void
pointer (ie basically none), but you know it's a pointer to this
undefined type. Python simply doesn't have an equivalent, since there
is no concept of typed pointers, but the nearest equivalent would be
making it legal in type hints.

Python DOES, however, have first-class types. They are real objects
and can be examined at run-time. This proposed feature isn't analogous
to C's structs, since C types its variables rather than its objects.

> > According to this proposal, it is entirely possible to continue a
> > class more than once, with just some fiddling with dunders.
>
> No, it's not. As has been explained upthread, stuff is done
> when finalising a class that can't be repeated.

>From the OP:

On Sat, 23 Apr 2022 at 11:16, Larry Hastings <la...@hastings.org> wrote:
> #### Semantics of forward-declared class objects
> ...
> However, the user isn't permitted to instantiate a forward-declared
> class object until after the corresponding `continue class X`.
> We ensure this with a new dunder attribute, `__forward__`,
> which if present tells the Python runtime that this is a
> forward-declared class object.  The `continue class` statement
> would delete this attribute from the object, after which it
> could be instantiated.
>
> (Users could work around this constraint, or even delete `__forward__`
> if they so chose--again, the "consenting adults" rule applies.)
> ...
> `continue class` may only be run on a class once.
> (As Eric V. Smith pointed out in response to an early version of
> this proposal, allowing multiple "continue" declarations on the
> same class would lead directly to language-condoned monkey-patching.)

So unless I'm horrifically misreading this, the only thing stopping
you from doing multiple continues is this attribute which says that
it's a forward-declared class. Removing this would allow you to work
around this constraint, which exists solely to avoid the perception of
"language-condoned monkey-patching".

The proposal explicitly lays out that a forward-declared class IS a
class, and can be used in a number of basic ways (but can't be
instantiated). The "continue class" statement removes this flag, but
you can mess with that flag and re-continue a class, or instantiate a
non-completed 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/7CVJPKQ53K2BOQ4KOOXWLZ7LOX4G2NQH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to