ID EN
Enum

STRICT

Python 3.11

Out-of-range values cause a ValueError to be raised. This is the default for Flag:

Syntax

PYTHON
STRICT

Examples

Example 1
PYTHON
>>> from enum import Flag, STRICT, auto
>>> class StrictFlag(Flag, boundary=STRICT):
...     RED = auto()
...     GREEN = auto()
...     BLUE = auto()
>>> StrictFlag(2**2 + 2**4)
Traceback (most recent call last):
...
ValueError: <flag 'StrictFlag'> invalid value 20
    given 0b0 10100
  allowed 0b0 00111

See Also

ValueError Flag