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 nothing" dunders such as `__add__` 
aren't defined.

I've tried searching for answers, and looked at the source code for rich 
comparisons here:

https://github.com/python/cpython/blob/3.8/Objects/object.c

read the information here and in the PEP:

https://docs.python.org/3/c-api/object.html#c.PyObject_RichCompare

https://www.python.org/dev/peps/pep-0207/

I'm not sure if I'm looking in the right places, or if I even understand 
exactly what I'm looking at, but I think the relevent code is in 
typeobject.c, which defines a type:


    PyTypeObject PyBaseObject_Type = {
        PyVarObject_HEAD_INIT(&PyType_Type, 0)
        "object",                                   /* tp_name */
        ...


and then sets tp_richcompare to `object_richcompare`. I guess that is 
enough to define the dunder methods?

Since (as far as I can tell) they don't do anything, why do they exist?


Thanks in advance.



-- 
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/TWL5VMCXC6SUEGRQ36CAMPA273E4O2TZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to