[Python-ideas] [[Python-Dev] PyObject_RichCompareBool identity shortcut] About specializing comparing objects in collections

Steven D'Aprano steve at pearwood.info
Fri Apr 29 10:03:35 CEST 2011


ZS wrote:
> Returning to the original topic post on the comparison of objects in
> containers ...
> Could be asked to enter a special method __equals__ of objects for
> comparison in containers (by default, if it is not defined - use usual
> method for compatibility), just as is done in C# (it's special
> object's method Equals is used to compare items in the collection).


I'm not sure I understand what that would gain us, have I missed something?

Currently, containers use identity tests as an optimization to avoid 
calling (potentially expensive) __eq__. What benefit do you have in mind 
to have containers call (potentially expensive) __equals__ instead of 
__eq__?

It might help if you tell us what you envisage float would have as 
__equals__ instead of the current __eq__.



-- 
Steven




More information about the Python-ideas mailing list