Python Glossary Русский

Python 3.11+enumterm

enum.member

members

A wrapper that forces a value to become an enum member (Python 3.11+); useful for functions and descriptors.

Syntax

X = enum.member(value)

It exists for the cases where the usual Enum rules work against you: a function, lambda, descriptor or nested class written in the enum body is treated as a method, not a member. Wrapping it makes it a real member with .name and .value. For plain numbers and strings the wrapper is pointless, and before Python 3.11 people faked it by hiding the callable inside something like functools.partial.

Examples

import enum
class C(enum.Enum):
    X = enum.member(1)
print(C.X.value)   # → 1

See also

Open in the full glossarydocs.python.orgReport an inaccuracy