Enumeration idioms: Values from different enumerations

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Dec 16 19:23:56 EST 2005


On Fri, 16 Dec 2005 02:43:35 -0800, Ben Sizer wrote:

> 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

Okay, so I was wrong to say that nobody was seriously suggesting that sort
of behaviour. 

> 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.)

Enums are not conceptually subclasses of integers. Integers just happen to
be a useful method to implement enumerations.


-- 
Steven.




More information about the Python-list mailing list