@@ -2462,19 +2462,25 @@ Determining the appropriate metaclass
24622462.. index ::
24632463 single: metaclass hint
24642464
2465- The appropriate metaclass for a class definition is determined as follows :
2465+ The appropriate metaclass for a class definition is determined in two steps :
24662466
2467- * if no bases and no explicit metaclass are given, then :func: `type ` is used;
2467+ 1) a candidate metaclass is determined as follows:
2468+
2469+ * if no bases and no explicit metaclass are given, then :func: `type ` is used
2470+ as candidate;
2471+ * if bases are defined, the metaclass of the first base is used as candidate;
24682472* if an explicit metaclass is given and it is *not * an instance of
2469- :func: `type `, then it is used directly as the metaclass;
2470- * if an instance of :func: `type ` is given as the explicit metaclass, or
2471- bases are defined, then the most derived metaclass is used.
2472-
2473- The most derived metaclass is selected from the explicitly specified
2474- metaclass (if any) and the metaclasses (i.e. ``type(cls) ``) of all specified
2475- base classes. The most derived metaclass is one which is a subtype of *all *
2476- of these candidate metaclasses. If none of the candidate metaclasses meets
2477- that criterion, then the class definition will fail with ``TypeError ``.
2473+ :func: `type `, then it is used directly as the metaclass and step 2 is skipped.
2474+
2475+ 2) bases, if present, are traversed left-to-right, and the most derived
2476+ metaclass is determined as follows:
2477+
2478+ * if the metaclass of the current candidate is a subtype of the metaclass of
2479+ the current base, updated the candidate to the metaclass of the base and
2480+ continue to the next base;
2481+ * if the current candidate is a subtype of the metaclass of the current base,
2482+ continue to the next base;
2483+ * else raise a :exc: `TypeError `.
24782484
24792485
24802486.. _prepare :
0 commit comments