Message226395
Yes, sorry I forgot about that. Here is a minimal example:
from enum import EnumMeta, Enum
from types import DynamicClassAttribute
class _MultiMeta(EnumMeta):
def __init__(enum_class, cls, bases, classdict):
# make sure we only have tuple values, not single values
for member in enum_class.__members__.values():
if not isinstance(member._value_, tuple):
raise ValueError('{!r}, should be tuple'.format(member._value_))
def __call__(cls, suit):
for member in cls:
if suit in member._value_:
return member
return super().__call__(suit)
class MultiValueEnum(Enum, metaclass=_MultiMeta):
@DynamicClassAttribute
def value(self):
"""The value of the Enum member."""
return self._value_[0]
class IncorrectAliasBehavior(MultiValueEnum):
first = 1, 2, 3
second = 4, 5, 6
alias_to_first = 1, 2, 3
When you call IncorrectAliasBehavior.alias_to_first, the documentation says it should return IncorrectAliasBehavior.first, but in this case it returns IncorrectAliasBehavior.alias_to_first, because canonical_member.value is referenced on line 162, and so it returns the redefined value, not the internally used one.
This was very confusing for me. |
|
Date |
User |
Action |
Args |
2014-09-05 01:09:03 | kissgyorgy | set | recipients:
+ kissgyorgy, barry, eli.bendersky, ethan.furman |
2014-09-05 01:09:03 | kissgyorgy | set | messageid: <1409879343.48.0.131364726482.issue22339@psf.upfronthosting.co.za> |
2014-09-05 01:09:03 | kissgyorgy | link | issue22339 messages |
2014-09-05 01:09:02 | kissgyorgy | create | |
|