Python 3.11+enumterm
enum.ReprEnum
enum kinds
The base for IntEnum/StrEnum: keeps the mixed-in type's repr (3.11+).
Syntax
class C(int, enum.ReprEnum): ...
Despite the name, ReprEnum leaves repr alone (<Size.S: 'small'>) and instead borrows str() and format() from the mixed-in type. It exists because 3.11 made plain mixins like class Foo(str, Enum) print as Foo.A, and IntEnum/StrEnum had to be shielded from that change. Inherit from it when you build your own mixin enum and want members to render as their values in f-strings.
Examples
import enum
print(issubclass(enum.IntEnum, enum.ReprEnum)) # → True
import enum
class Size(int, enum.ReprEnum): BIG = 10
print(Size.BIG) # → 10
print(repr(Size.BIG)) # → <Size.BIG: 10>
import enum
class Plain(enum.Enum): BIG = 10
print(Plain.BIG) # → Plain.BIG
See also
Open in the full glossarydocs.python.orgReport an inaccuracy