23 Sep
2020
23 Sep
'20
12:05 a.m.
On 23/09/20 12:20 am, Steven D'Aprano wrote:
Presumably back when rich comparisons were added, the choice would have been:
- add one tp_richcompare slot to support all six methods; or
- add six slots, one for each individual dunder
in which case the first option wastes much less space.
I don't know the exact reasons, but it might also have been because the implementations of the six dunders are usually very closely related, so having just one function to implement at the C level is a lot easier for most types. Also remember that before tp_richcompare existed there was only tp_compare, which also handled all the comparisons, so tp_richcompare was likely seen as a generalisation of that. -- Greg