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 ethan.furman
Recipients barry, eli.bendersky, ethan.furman, kissgyorgy
Date 2014-09-06.02:54:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1409972059.24.0.618017657573.issue22339@psf.upfronthosting.co.za>
In-reply-to
Content
Right.  We can still use the alias machinery to accomplish this task for us, and avoid the metaclass hacking:

-- python2 sample code ------------------------------------
# -*- coding: utf-8 -*-
from enum import Enum

class MultiValueEnum(Enum):
    def __new__(cls, *values):
        obj = object.__new__(cls)
        obj._value_ = values[0]
        obj._all_values = values
        for alias in values[1:]:
            cls._value2member_map_[alias] = obj
        return obj
    def __repr__(self):
        return "<%s.%s: %s>" % (
             self.__class__.__name__,
             self._name_,
             ', '.join(["'%s'" % v for v in self._all_values])
             )

class Suits(MultiValueEnum):
    CLUBS =    '♣', 'c', 'C', 'clubs', 'club'
    DIAMONDS = '♦', 'd', 'D', 'diamonds', 'diamond'
    HEARTS =   '♥', 'h', 'H', 'hearts', 'heart'
    SPADES =   '♠', 's', 'S', 'spades', 'spade'

print(Suits.HEARTS)
print(repr(Suits.HEARTS))
print(Suits('d'))
print(Suits('club'))
print(Suits('S'))
print(Suits('hearts'))

----------------------------------------------------------------

And the output:

Suits.HEARTS
<Suits.HEARTS: '♥', 'h', 'H', 'hearts', 'heart'>
Suits.DIAMONDS
Suits.CLUBS
Suits.SPADES
Suits.HEARTS

----------------------------------------------------------------

I'm still going to fix the bug, though.  :)

Oh, the above does not fix the IncorrectAliasBehavior class, but honestly I'm not sure what you are trying to accomplish there.
History
Date User Action Args
2014-09-06 02:54:19ethan.furmansetrecipients: + ethan.furman, barry, eli.bendersky, kissgyorgy
2014-09-06 02:54:19ethan.furmansetmessageid: <1409972059.24.0.618017657573.issue22339@psf.upfronthosting.co.za>
2014-09-06 02:54:19ethan.furmanlinkissue22339 messages
2014-09-06 02:54:18ethan.furmancreate