This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kissgyorgy
Recipients barry, eli.bendersky, ethan.furman, kissgyorgy
Date 2014-09-05.01:09:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1409879343.48.0.131364726482.issue22339@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-09-05 01:09:03kissgyorgysetrecipients: + kissgyorgy, barry, eli.bendersky, ethan.furman
2014-09-05 01:09:03kissgyorgysetmessageid: <1409879343.48.0.131364726482.issue22339@psf.upfronthosting.co.za>
2014-09-05 01:09:03kissgyorgylinkissue22339 messages
2014-09-05 01:09:02kissgyorgycreate