[[Python-Dev] PyObject_RichCompareBool identity shortcut] About specializing comparing objects in collections
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). ----- Zaur
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
participants (2)
-
Steven D'Aprano
-
ZS