Python Glossary Русский

Python 3.11+enumterm

enum.verify

checks

A class decorator enforcing enum constraints (UNIQUE/CONTINUOUS/NAMED_FLAGS) at definition (3.11+).

Syntax

@enum.verify(enum.UNIQUE)

The check runs once, when the class is created — it is not runtime validation of values, and it needs Python 3.11+. The UNIQUE mode is exactly what the @unique decorator already does, so verify earns its place through the other two: CONTINUOUS demands values with no gaps between the lowest and the highest, and NAMED_FLAGS demands that every bit of a composite flag value be covered by a named member.

Examples

import enum
@enum.verify(enum.UNIQUE)
class C(enum.Enum):
    A = 1
    B = 2
print(len(C))   # → 2

See also

Open in the full glossarydocs.python.orgReport an inaccuracy