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: clarify comparison return values
Type: Stage:
Components: Documentation Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, jimjjewett
Priority: normal Keywords: patch

Created on 2006-11-24 07:24 by jimjjewett, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg51409 - (view) Author: Jim Jewett (jimjjewett) Date: 2006-11-24 07:24
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).
"""
msg51410 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-06 18:30
Fixed in rev. 54171, 54172 (2.5).
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44270
2006-11-24 07:24:11jimjjewettcreate