]> granicus.if.org Git - python/commitdiff
#6428: py3k requires that __bool__ return a bool (and not an int)
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 7 Jul 2009 00:43:08 +0000 (00:43 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 7 Jul 2009 00:43:08 +0000 (00:43 +0000)
Fix the error message and the documentation.

Doc/reference/datamodel.rst
Misc/NEWS
Objects/typeobject.c

index 21617062462aefa39be9f03175762384a4175e67..d0aa59fbc51d0c0fd0e75f4eeee4e7d37eb32c05 100644 (file)
@@ -1254,11 +1254,11 @@ Basic customization
    .. index:: single: __len__() (mapping object method)
 
    Called to implement truth value testing and the built-in operation
-   ``bool()``; should return ``False`` or ``True``, or their integer equivalents
-   ``0`` or ``1``.  When this method is not defined, :meth:`__len__` is called,
-   if it is defined, and the object is considered true if its result is nonzero.
-   If a class defines neither :meth:`__len__` nor :meth:`__bool__`, all its
-   instances are considered true.
+   ``bool()``; should return ``False`` or ``True``.  When this method is not
+   defined, :meth:`__len__` is called, if it is defined, and the object is
+   considered true if its result is nonzero.  If a class defines neither
+   :meth:`__len__` nor :meth:`__bool__`, all its instances are considered
+   true.
 
 
 .. _attribute-access:
index 2e040118ec020bbd55d5a6a6cb51ed8384a6617b..7cc3f368c31d0e9179ecb61b62db2e9ce2cb84c2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #6428: Since Python 3.0, the __bool__ method must return a bool
+  object, and not an int.  Fix the corresponding error message, and the
+  documentation.
+
 - The deprecated PyCObject has been removed.
 
 - Issue #6347: Include inttypes.h as well as stdint.h in pyport.h.
index 0e7954206bb1b7945ff2512cd20f30198cfa5deb..60483e718cdb4ced9f47d19d5b4a4c077ae0f3a5 100644 (file)
@@ -4807,10 +4807,8 @@ slot_nb_bool(PyObject *self)
                        }
                        else {
                                PyErr_Format(PyExc_TypeError,
-                                            "%s should return "
-                                            "bool or int, returned %s",
-                                            (using_len ? "__len__"
-                                                       : "__bool__"),
+                                            "__bool__ should return "
+                                            "bool, returned %s",
                                             Py_TYPE(temp)->tp_name);
                                result = -1;
                        }