Python Metaclasses in Eight Words

Python metaclasses, considered advanced programming and Python "black magick" (*) explained in eight words: The type of a class is a class. Here's what knowledge of Object Oriented theory and type systems permit you to deduce from this: Using the word "class", instead of "the type of a class is type" or even "the type of a class is a type, classes are types", implies that a user defined class can be a metaclass. This is indeed the case, and the point of metaclasses in Python. The type is responsible for creating new instances. So if the type of a class is a class then we can write classes that create classes. Indeed this is the primary usecase for metaclasses. (Deeper knowledge of Python, and the two phase object creation protocol, may lead you to deduce that this is done by overriding the __new__ method. If you're familiar with "type" as a class factory you can probably even guess the signature and that you must inherit from