[issue22339] Incorrect behavior when subclassing enum.Enum

Kiss György report at bugs.python.org
Sat Sep 6 02:43:35 CEST 2014


Kiss György added the comment:

> Is this a way to easily handle multiple aliases?

You mean this MultiValueEnum implementation? (If not I don't understand the question, could you elaborate?)

No, this is the opposite of aliases, because an alias is when the same value have multiple names, but this is when the values are used to lookup the same name.

I use it when very similar values have the same meaning like:

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


Also it can be used for ECP testing (Equivalence class testing) like this:

    from http.client import responses
    class ResponseEnum(MultiValueEnum):
        GOOD = [status for status in responses if 200 <= status <= 299]
        BAD = [status for status in responses if not (200 <= status <= 299)]

I did not think about this use case, but I think it's very interesting and useful.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22339>
_______________________________________


More information about the Python-bugs-list mailing list