Python 3.11+enumterm
enum.nonmember
members
A wrapper preventing a value from becoming an enum member (3.11+).
Syntax
H = enum.nonmember(value)
This is the mirror problem: any ordinary value in an Enum body silently becomes a member, counted by len(), yielded by iteration and reachable by value lookup, while nonmember keeps it an ordinary class attribute. Note that C.HELPER then gives you the raw value, with no .name or .value, and C(99) raises ValueError. A single leading underscore does not help — _X = 99 still becomes a member; only a private __X name is excluded, so a public constant needs nonmember.
Examples
import enum
class C(enum.Enum):
X = 1
HELPER = enum.nonmember(99)
print(C.HELPER) # → 99
print(len(C)) # → 1
See also
Open in the full glossarydocs.python.orgReport an inaccuracy