Op 2005-12-16, Ben Sizer schreef <[EMAIL PROTECTED]>:
> 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.)

I'm against it. I don't like the following returning True:

  ShirtSize.small in [ShirtSize.Medium, AppleSize.small]


I also think it may cause problems with other comparisons.

Supose the following:

  col = Enum('red', 'green', 'blue')
  paint = Enum('violet' , 'blue', 'red')

Then we get the following situation: 

  col.red == paint.red and col.blue == paint.blue

but

  col.red < col.blue and paint.blue < paint.red

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to