Author mark.dickinson
Recipients Eric.Wieser, Stephan Hoyer, mark.dickinson, rhettinger
Date 2017-04-24.07:21:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> could you point me to where this logic is implemented in CPython's source?

Most of the relevant code is in Objects/abstract.c and Objects/typeobject.c.

A BINARY_ADD opcode (for example) ends up calling PyNumber_Add:

which in turn calls binary_op1, where you see an explicit check for the nb_add slots of the two operands being identical:

For a user-defined class, the slots themselves are defined in typeobject.c. Here's where nb_add is defined:

and here's the explicit check for overloading in the SLOT1BIN macro definition:

There's also an explicit test for the arithmetic operation behaviour in Lib/test/ In short, I doubt this was ever a bug: everything points to this being a deliberate design decision. I hope someone on python-ideas can elaborate on the rationale behind that design decision (and also on why that rationale doesn't apply to comparisons).

In contrast, it does seem plausible to me that the *comparison* failure to check for an explicit override may have been accidental.
Date User Action Args
2017-04-24 07:21:50mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, Eric.Wieser, Stephan Hoyer
2017-04-24 07:21:50mark.dickinsonsetmessageid: <>
2017-04-24 07:21:50mark.dickinsonlinkissue30140 messages
2017-04-24 07:21:49mark.dickinsoncreate