Ethan Furman added the comment: 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. ---------- stage: -> patch review type: enhancement -> behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22339> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com