[Python-Dev] operator precedence of __eq__, __ne__, etc, if both object have implementations

Jared Flatow jflatow at gmail.com
Tue Sep 22 16:20:04 CEST 2009

This might help:


Here is the most relevant part (quoting Guido):

 > Does it help if I tell you that for "x <binop> y" we always try
 > x.__binop__(y) before trying y.__reverse_binop__(x), *except* in the
 > case where y is an instance of a subclass of the class of x?


On Sep 22, 2009, at 7:06 AM, Chris Withers wrote:

> Hi All,
> I didn't see any docs on this:
> http://docs.python.org/reference/datamodel.html?highlight=__eq__#object.__eq__
> Where are the specifications on what happens if two objects are  
> compared and both have implementations of __eq__? Which __eq__ is  
> called? What happens if the first one called returns False? Is the  
> second one called? What is one implements __eq__ and the other __ne__?
> If I've missed something, please point me in the right direction.
> To all those about to tell me to go read the source: that's not good  
> enough here. I'm hoping there *are* "official" rules for how these  
> interact and they just need better linking in, otherwise, I worry  
> that IronPython could do one thing, Jython another and CPython a  
> third...
> cheers,
> Chris
> -- 
> Simplistix - Content Management, Batch Processing & Python Consulting
>           - http://www.simplistix.co.uk
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/jflatow%40gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090922/5d2ffc0f/attachment.htm>

More information about the Python-Dev mailing list