Chapter 3. Data model 34 The Python Language Reference, Release 3.9.5 Note: The metaclass hint metaclass is consumed by the rest of the type machinery, and is never passed to __init_subclass__ implementations. The actual metaclass (rather than the explicit hint) can be accessed as$_{type(cls)}$ . New in version 3.6. By default, classes are constructed using type() . The class body is executed in a new namespace and the class name is bound locally to the result of type(name, bases, namespace) . The class creation process can be customized by passing the$_{metaclass}$ keyword argument in the class definition line, or by inheriting from an existing class that included such an argument. In the following example, both MyClass and MySubclass are instances of Meta : Any other keyword arguments that are specified in the class definition are passed through to all metaclass operations described below. When a class definition is executed, the following steps occur: • MRO entries are resolved; • the appropriate metaclass is determined; • the class namespace is prepared; • the class body is executed; • the class object is created. Resolving MRO entries Metaclasses If a base that appears in class definition is not an instance of$_{type}$, then an$_{__mro_entries__}$ method is searched on it. If found, it is called with the original bases tuple. This method must return a tuple of classes that will be used instead of this base. The tuple may be empty, in such case the original base is ignored. The appropriate metaclass for a class definition is determined as follows: See also: PEP 560 - Core support for typing module and generic types • if an instance of$_{type()}$ is given as the explicit metaclass, or bases are defined, then the most derived metaclass is used. • if an explicit metaclass is given and it is not an instance of$_{type()}$ , then it is used directly as the metaclass; • if no bases and no explicit metaclass are given, then$_{type()}$ is used; Determining the appropriate metaclass classMeta (type): pass classMyClass (metaclass =Meta): pass classMySubclass (MyClass): pass