Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
097cd072
Commit
097cd072
authored
Jul 07, 2009
by
Amaury Forgeot d'Arc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6428: py3k requires that __bool__ return a bool (and not an int)
Fix the error message and the documentation.
parent
dd07ebb4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
9 deletions
+11
-9
Doc/reference/datamodel.rst
Doc/reference/datamodel.rst
+5
-5
Misc/NEWS
Misc/NEWS
+4
-0
Objects/typeobject.c
Objects/typeobject.c
+2
-4
No files found.
Doc/reference/datamodel.rst
View file @
097cd072
...
...
@@ -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:
...
...
Misc/NEWS
View file @
097cd072
...
...
@@ -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.
...
...
Objects/typeobject.c
View file @
097cd072
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment