[issue34909] StrEnum subclasses cannot be created
Ethan Furman
report at bugs.python.org
Fri Oct 5 16:12:48 EDT 2018
New submission from Ethan Furman <ethan at stoneleaf.us>:
from enum import Enum, unique
class StrEnum(str, Enum):
def __new__(cls, *args, **kwargs):
for a in args:
if not isinstance(a, str):
raise TypeError("Enumeration '%s' (%s) is not"
" a string" % (a, type(a).__name__))
return super(StrEnum, cls).__new__(cls, *args, **kwargs)
@unique
class Decision(StrEnum):
"""Decision results/strategy enumeration."""
REVERT = "REVERT"
REVERT_ALL = "REVERT_ALL"
RETRY = "RETRY"
---
Traceback (most recent call last):
File "test", line 14, in <module>
class Decision(StrEnum):
File ".../cpython/Lib/enum.py", line 222, in __new__
enum_member._value_ = member_type(*args)
File ".../cpython/Lib/enum.py", line 309, in __call__
return cls.__new__(cls, value)
File ".../cpython/Lib/enum.py", line 545, in __new__
return cls._missing_(value)
File ".../cpython/Lib/enum.py", line 558, in _missing_
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 'REVERT' is not a valid StrEnum
----------
assignee: ethan.furman
keywords: 3.7regression
messages: 327182
nosy: ethan.furman, ned.deily
priority: release blocker
severity: normal
stage: test needed
status: open
title: StrEnum subclasses cannot be created
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34909>
_______________________________________
More information about the Python-bugs-list
mailing list