Python Equality Precedence
Solution 1:
This is documented under the numeric operations, further down the page, with an explanation for why it works that way:
Note: If the right operand’s type is a subclass of the left operand’s type and that subclass provides the reflected method for the operation, this method will be called before the left operand’s non-reflected method. This behavior allows subclasses to override their ancestors’ operations.
The Python 3 documentation additionally mentions it in the section you were looking at:
If the operands are of different types, and right operand’s type is a direct or indirect subclass of the left operand’s type, the reflected method of the right operand has priority, otherwise the left operand’s method has priority. Virtual subclassing is not considered.
Post a Comment for "Python Equality Precedence"