[ python-Bugs-1655683 ] 3.4.1 comparison methods content

SourceForge.net noreply at sourceforge.net
Fri Feb 9 13:54:25 CET 2007


Bugs item #1655683, was opened at 2007-02-09 02:48
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1655683&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: Python 2.5
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Jeffrey Miller (jsmgoogle)
Assigned to: Nobody/Anonymous (nobody)
Summary: 3.4.1 comparison methods content

Initial Comment:
From: Jeffrey Miller <jsmiller at 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.
"""


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2007-02-09 13:54

Message:
Logged In: YES 
user_id=21627
Originator: NO

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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1655683&group_id=5470


More information about the Python-bugs-list mailing list