Enumeration idioms: Values from different enumerations

Ben Sizer kylotan at gmail.com
Fri Dec 16 05:43:35 EST 2005


Ben Finney wrote:
> The problem with "is the same value" as an explanation for '==' is
> that it doesn't help in cases such as::
>
>     >>> ShirtSize = Enum('small', 'medium', 'large')
>     >>> AppleSize = Enum('small', 'large')
>
> What should be the result of this comparison::
>
>     >>> ShirtSize.small == AppleSize.small
>
> Are they "the same value"? They're both "small" (and they both coerce
> to the same string value, and in this case the same integer value).

Is it possible to make it have the following sort of behaviour? :

>>> ShirtSize.small == AppleSize.small
True
>>> ShirtSize.small is AppleSize.small
False

It works for comparing a boolean (True) vs. an integer (1), so it has
some sort of precedent. (Especially if you make the tenuous assumption
that True,False are language-supported 'enums' for 0 and 1.)

-- 
Ben Sizer




More information about the Python-list mailing list