6.4 Metaclasses
As we noted earlier, creating a new class involves work done by the type class. The job of the type class is to create an empty class object so the various definitions and attribute assignment statements can then initialize the final, usable class we need for our application.
Figure 6.3 shows how type works:
The class statement is used to locate the metaclass; if no special metaclass= is provided, then the type class is used. The type class will prepare a new, empty dictionary, called a namespace, and then the various statements in the class populate this container with attributes and method definitions. Finally, the ”new” step completes the creation of the class; this is generally where we can make our changes.
Figure 6.4 shows how a new class, SpecialMeta, builds a new class for us: