Python Glossary Русский

Python 3.11+enumterm

enum.EnumType

metaclass

The metaclass of all enums: it turns a class of constant attributes into an Enum (checks uniqueness, creates members). The current name since Python 3.11.

Syntax

class E(enum.Enum): ...  # type(E) is enum.EnumType

You rarely name it directly, yet it is the reason len(Color), iterating a Color, Color['RED'] and Color(1) all work: those operations live on the metaclass, not on Enum itself. Before Python 3.11 it was called EnumMeta, and the old name still works as an alias, so existing code kept running. Subclassing it only pays off when you build your own flavour of enumeration with custom member lookup.

Examples

import enum
class Color(enum.Enum):
    RED = 1
print(type(Color).__name__)   # → EnumType

See also

Open in the full glossarydocs.python.orgReport an inaccuracy