A metaclass is the class of a class; type is the default metaclass for every class
In Python, classes are objects. Their type is a metaclass, and by default that metaclass is type. When the interpreter executes a class statement, it collects the namespace and calls metaclass(name, bases, namespace), which returns the class object. So every class is an instance of its metaclass, and type is the root metaclass that builds classes. A custom metaclass subclasses type and overrides new or init to transform the class at creation time. The most common need is validation or registration of all subclasses, which can also be done with init_subclass or a class decorator.
type(obj) returns the class of an instance; type(SomeClass) returns its metaclass, usually type.
Class creation order: prepare produces the namespace dict, metaclass new builds the class, then init finalizes it.
type(name, bases, dict) is the three-argument form that builds a class dynamically.
ABCMeta is the canonical built-in metaclass; it powers abc.ABC and virtual subclass registration.
Trade-off: metaclasses are powerful but affect every subclass, can conflict when multiple bases have different metaclasses, and complicate debugging.
Common mistake: reaching for a metaclass when init_subclass or a class decorator would be simpler and safer.
Version note: init_subclass and set_name were added in 3.6 specifically to reduce the need for custom metaclasses.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience