__coerce__ called for dict keys?
Paul D. Lusk
plusk at radford.edu
Sun Nov 3 15:08:36 EST 2002
aahz at pythoncraft.com (Aahz) wrote in news:aq3gfq$356$1 at panix1.panix.com:
> In article <Xns92B7939E346B6ID134675userdfncisd at 130.133.1.4>,
> Paul D. Lusk <plusk at radford.edu> wrote:
>>
>> I think you need __eq__ rather than __cmp__ in 2.2
>
> Nope. __eq__ gets called before __cmp__, but __cmp__ gets called if
> __eq__ isn't defined. See PEP 207.
Aahz is, of course, correct. The reason I thought you needed __eq__ was
because I was using a str subclass that I had created. I'd adapted it from
something that been posted here. It had __cmp__ defined, but not __eq__,
and I got _interesting_ results when I tried to use it as dict key. You do
need _eq_ if your parent class defines __eq_.
Paul
More information about the Python-list
mailing list