Author ethan.furman
Recipients ethan.furman, ned.deily
Date 2018-10-05.20:12:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538770368.25.0.545547206417.issue34909@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-10-05 20:12:48ethan.furmansetrecipients: + ethan.furman, ned.deily
2018-10-05 20:12:48ethan.furmansetmessageid: <1538770368.25.0.545547206417.issue34909@psf.upfronthosting.co.za>
2018-10-05 20:12:48ethan.furmanlinkissue34909 messages
2018-10-05 20:12:48ethan.furmancreate