Python metaclasses: How type.__new__ and type.__init__ create classes

Python metaclasses: How type.__new__ and type.__init__ create classes

A Python class is an instance of type. So type.__new__ and type.__init__ create the class and set attributes.

Consider MyType, a subclass of type, setting some attributes in its __init__.

MyType is a *metaclass*, used like this:

class MyClass(metaclass=MyType):
    pass