[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-23 Thread Jeff Allen
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

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-23 Thread Serhiy Storchaka
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

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread 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 case the first option wastes much less space. I don

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Nick Coghlan
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

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Steven D'Aprano
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__,

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Serhiy Storchaka
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

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Emily Bowman
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