On 4/23/22 00:53, Steven D'Aprano wrote:
It's a "forward-declared class object". It's the real class object, but
it hasn't been fully initialized yet, and won't be until the "continue
class" statement.
The only thing that makes it not fully initialised is that it has a bozo
bit dunder "__forward__" instructing the interpreter to disallow
instantiation. Yes?
If I take that class object created by `forward class X`, and delete the
dunder, there is no difference between it and other regular classes. Am
I correct?
No, there are several differences.
* It still has the "dict-like object" returned by
metaclass.__prepare__, rather than its final dict.
* Its class body hasn't been called yet, so it likely doesn't have any
of its important dunder methods.
* It hasn't had its BaseClass.__init_subclass__ called yet.
* It hasn't had its metaclass.__init__ called yet.
The "forward-declared class object" is in a not-yet-fully initialized
state, and is not ready for use as a class.
From my perspective, the "__forward__" attribute is an internal
implementation detail, and something that user code should strictly
leave alone. But if it's considered too dangerous to expose to users,
we could hide it in the class object and not expose it to users. I'm
not convinced that's the right call; I think the Consenting Adults rule
still applies. Python lets you do crazy things like assigning to
__class__, and resurrecting objects from inside their __del__; manually
removing __forward__ seems like it falls into the same category. It's
not recommended, and we might go so far as to say doing that results in
undefined behavior. But Python shouldn't stand in your way if you
really think you need to do it for some reason.
//arry/
_______________________________________________
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/2XDQGNBYQMN6M7Y5JNZA26JX5XS5AYIF/
Code of Conduct: http://python.org/psf/codeofconduct/