__lt__ slowing the "in" operator even if not called

Steven Bethard steven.bethard at gmail.com
Fri Jun 16 11:36:41 EDT 2006


Emanuele Aina wrote:
> andrewdalke at gmail.com dettagliò:
> 
>>> Someone can explain me why?
>> The list's __contains__ method is very simple
> 
> [...]
> 
>> So if you define "__lt__" in your object then the type gets a richcmp
>> function and your == test implicit in the 'in' search always incurs the
>> cost of figuring out that "__eq__" is not defined.
> 
> Thank you for the detailed explanation! :)
> 
> Do you think I should report this as a performance bug, maybe with the
> 'wishlist' priority, or I should accept the truth and hope for better
> luck next time? ;)

It certainly wouldn't hurt to report it.  But I suspect it's not ever 
going to get "fixed".  Classes with a __lt__ but no __eq__ really aren't 
that common.

STeVe



More information about the Python-list mailing list