This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 3.4.1 comparison methods content
Type: Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: jsmgoogle, loewis
Priority: normal Keywords:

Created on 2007-02-09 01:48 by jsmgoogle, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg31215 - (view) Author: Jeffrey Miller (jsmgoogle) Date: 2007-02-09 01:48
From: Jeffrey Miller <jsmiller@google.com>

At this URL and this section of the reference:

http://docs.python.org/ref/customization.html

3.4.1 Basic Customization

The existing text reads, in part:

"""
    There are no reflected (swapped-argument) versions of these methods (to be used when the left argument does not support the operation but the right argument does); rather, __lt__() and __gt__() are each other's reflection, __le__() and __ge__() are each other's reflection, and __eq__() and __ne__() are their own reflection.
"""

but is incorrect.  Although __le__ and __ge__ are symmetric, as are __lt__ and __gt__, they are not boolean inverse operations if the arguments are swapped.

Instead the text should pair __lt__ with __ge__, __le__ with __gt__ .

Correcting the given text, it should read:

"""
    There are no reflected (swapped-argument) versions of these methods (to be used when the left argument does not support the operation but the right argument does); rather, __lt__() and __ge__() are each other's reflection, __le__() and __gt__() are each other's reflection, and __eq__() and __ne__() are their own reflection.
"""
msg31216 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-02-09 12:54
I cannot see a bug there.

The text doesn't talk about boolean inverse operations, it talks about reflected operations, and defines that term as "to be used when the left argument does not support the operation but the right argument does")

Consider this code:

>>> class A:
...   pass
... 
>>> class B:
...   def __gt__(self, other):
...     print "gt"
...     return True
...   def __ge__(self, other):
...     print "ge"
...     return True
... 
>>> A()<B()
gt
True

According to your "corrected" text, lack of __lt__ in class A should cause __ge__ of class B to be called. As you can see, it calls __gt__ instead (just as the documentation predicts). Indeed, x<y should be considered equal to y>x.

Closing the report as invalid.
msg31217 - (view) Author: Jeffrey Miller (jsmgoogle) Date: 2007-02-09 18:35
I stand corrected.  Thank you for taking the time to elucidate. (A <= B is equivalent to the swapped operation B >= A)
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44562
2007-02-09 01:48:41jsmgooglecreate