On this page
enum.global_enum
Prev: enum.FlagBoundary | Up: enum | Next: enum.global_enum_repr
Rel: enum.auto, enum.Enum, enum.EnumCheck, enum.EnumDict
Ref: docs.python.org — enum.global_enum
Tags: #public #python3 #stdlib #enum
Import
import enum
from enum import global_enum
Signature & Overview
enum.global_enum(cls, update_str=False)
decorator that makes the repr() of an enum member reference its module instead of its class; also exports all members to the enum's module's global namespace
Usage
from enum import IntEnum, global_enum
@global_enum
class Signal(IntEnum):
STOP = 1
GO = 2
assert repr(Signal.STOP) == "<STOP: 1>"
Gotchas
- Python 3.11+: Adjusts
str()andrepr()for enums whose members are exported into module globals (likere.RegexFlagorsocket.AddressFamily).
REPL Inspect
from enum import global_enum
help(global_enum)
Linked from
Related notes
- tuts/python3/stdlib_module/enum/FlagBoundary Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/global_enum_repr Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/auto Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/Enum Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumCheck Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumDict Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/enum/EnumMeta shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumType shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/Flag shared tags: #enum, #stdlib