On this page
enum.ReprEnum
Prev: enum.property | Up: enum | Next: enum.StrEnum
Rel: enum.auto, enum.Enum, enum.EnumCheck, enum.EnumDict
Ref: docs.python.org — enum.ReprEnum
Tags: #public #python3 #stdlib #enum
Import
import enum
from enum import ReprEnum
Signature & Overview
enum.ReprEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)
Only changes the repr(), leaving str() and format() to the mixed-in type.
Usage
from enum import ReprEnum
class FloatEnum(float, ReprEnum):
HALF = 0.5
ONE = 1.0
assert str(FloatEnum.HALF) == "0.5"
assert repr(FloatEnum.HALF) == "<FloatEnum.HALF: 0.5>"
Gotchas
- Python 3.11+ base for mixed-in enums: Preserves
Enum's informativerepr()while letting the mixin (int,str,float) controlstr()andformat().
REPL Inspect
from enum import ReprEnum
help(ReprEnum)
Linked from
Related notes
- tuts/python3/stdlib_module/enum/property Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/StrEnum 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