[Python-Dev] PEP 422: Simpler customisation of class creation

Nick Coghlan ncoghlan at gmail.com
Sun Sep 15 16:40:48 CEST 2013

On 16 September 2013 00:19, Ethan Furman <ethan at stoneleaf.us> wrote:
> Three questions:
> Would the new __initclass__ function be usable with actual full-blown
> metaclasses?

Sure (as long as the metaclass in question called it at the
appropriate time, which those inheriting from type would do

> The PEP says this:
>> If present on the created object, this new hook will be called by the
>> class creation machinery after the __class__ reference has been initialised.
> Given that statement, and this example:
>     class A:
>         def __initclass__(cls):
>             # do stuff
>     class B(A):
>         pass
> am I correct that A's __initclass__ will not run when B is created?

No, that would be pointless (since that's the way class decorators
already behave). "present on the created object" means "hasattr(cls,
'__initclass__') returns True.

> Where are we at with being ready for pronouncement?

The PEP needs to be updated to incorporate the feedback from the last
time I proposed it for inclusion. That's not going to happen for 3.4,
I just forgot to mark it as Deferred - fixed now.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list