On 22/09/2020 12:13, Serhiy Storchaka wrote:
Because object.__eq__ and object.__ne__ exist.
I didn't quite get the logic of this. In case anyone (not Steven) is
still puzzled as I was, I think one could say: ... because
tp_richcompare is filled, *so that* object.__eq__ and object.__ne__ will
23.09.20 03:05, Greg Ewing пише:
> 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
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
On Tue., 22 Sep. 2020, 10:25 pm Steven D'Aprano,
wrote:
> On Tue, Sep 22, 2020 at 02:13:46PM +0300, Serhiy Storchaka wrote:
> > 22.09.20 12:48, Steven D'Aprano пише:
> > > Why does `object` define rich comparison dunders `__lt__` etc?
>
> > Because object.__eq__ and object.__ne__ exist. If you de
On Tue, Sep 22, 2020 at 02:13:46PM +0300, Serhiy Storchaka wrote:
> 22.09.20 12:48, Steven D'Aprano пише:
> > Why does `object` define rich comparison dunders `__lt__` etc?
> Because object.__eq__ and object.__ne__ exist. If you define slot
> tp_richcompare in C, it is exposed as 6 methods __eq__,
22.09.20 12:48, Steven D'Aprano пише:
> Why does `object` define rich comparison dunders `__lt__` etc?
>
> As far as I can tell, `object.__lt__` etc always return NotImplemented.
> Merely inheriting from object isn't enough to have comparisons work. So
> why do they exist at all? Other "do nothi
NotImplemented is like a pure virtual function; failing to implement it
tells you that you forgot part of the contract, except at runtime instead
of compile time. So if you never need them, you're free to elide them, but
if you want full compatibility, you need to implement every part of it.
If so