[Python-Dev] operator precedence of eq, ne, etc, if both object have implementations (original) (raw)

Willem Broekema metawilm at gmail.com
Tue Sep 22 17:23:03 CEST 2009


On Tue, Sep 22, 2009 at 5:12 PM, Mark Dickinson <dickinsm at gmail.com> wrote:

- Exception to the previous item: if the left operand is an instance of a built-in type or a new-style class, and the right operand is an instance of a proper subclass of that type or class AND overrides the base’s rop() method, the right operand’s rop() method is tried before the left operand’s op() method.

The AND above (which I uppercased) is subtle but important. In the "x op y" case with y being of a subclass of the class of x, if there is no class in between x and y (excluding x, including y) that overrides the rop method, then y,rop(x) is not tried before x.op(y).

It's easy for other implementations to get this wrong. :)



More information about the Python-Dev mailing list