It's not a bug, it's just bypassing steps in the Py3 dynamic class definition process. is the API to use to invoke the full metaclass machinery, including namespace preparation. goes into more detail on how that works (calling the metaclass constructor is the last step, after the namespace has already been prepared and populated).


On Tue., 2 Jun. 2020, 5:22 am Ethan Furman, <> wrote:
 From stackoverflow [1]

   class Meta1(type):
       def __prepare__(mcs, name, bases):
           print('call prepare')
           return {}
       def __new__(mcs, name, bases, parameters):
           return super().__new__(mcs, name, bases, parameters)

   class A(metaclass=Meta1):

   type('C', (A, ), {})

output is:

   call prepare

(just the once, not twice)

The behavior of `type()` not calling `__prepare__()` has been constant since 3.3.

Is it a bug?


Python-Dev mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: