[Patches] [ python-Patches-1602128 ] clarify comparison return values

SourceForge.net noreply at sourceforge.net
Tue Mar 6 19:30:23 CET 2007


Patches item #1602128, was opened at 2006-11-24 07:24
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1602128&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.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Jim Jewett (jimjjewett)
Assigned to: Nobody/Anonymous (nobody)
Summary: clarify comparison return values

Initial Comment:
In the Language Reference section 3.4.1 (http://docs.python.org/ref/customization.html for version 2.5), in the first paragraph where it describes __lt__, __le__, __eq__, __ne__, __gt__, and __ge__,

It should mention the special case of NotImplemented, so that people will not be reluctant to return it.  (The fourth paragraph suggests returning NotImplemented, but the first suggests that *any* return value will be converted to a boolean, so that NotImplented would mean "True")

Please change:

"""These methods can return any value, but if the comparison operator is used in a Boolean context, the return value should be interpretable as a Boolean value, else a TypeError will be raised. By convention, False is used for false and True for true."""

to:

"""When an object does not know how to compute a meaningful result, it should return the singleton  NotImplemented, in case the other object implements the reflected comparison.

By convention, a successful comparison should return either True or False.  If any other object is returned in a Boolean context, python will implicitly call bool(result).
"""

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

>Comment By: Georg Brandl (gbrandl)
Date: 2007-03-06 18:30

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

Fixed in rev. 54171, 54172 (2.5).

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

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


More information about the Patches mailing list