[Python-checkins] bpo-30803: clarify truth value testing documentation (#2508)

Terry Jan Reedy webhook-mailer at python.org
Sat Jul 29 15:18:16 EDT 2017


https://github.com/python/cpython/commit/caa1280d1ee5f828f346b585169a7592371d3faa
commit: caa1280d1ee5f828f346b585169a7592371d3faa
branch: master
author: Peter Thomassen <peterthomassen at users.noreply.github.com>
committer: Terry Jan Reedy <tjreedy at udel.edu>
date: 2017-07-29T15:18:13-04:00
summary:

bpo-30803: clarify truth value testing documentation (#2508)

Initial patch by Peter Thomassen.

files:
A Misc/NEWS.d/next/Documentation/2017-07-29-14-55-50.bpo-30803.6hutqQ.rst
M Doc/library/stdtypes.rst

diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 564579e70c5..2fce851e2e0 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -39,31 +39,26 @@ Truth Value Testing
    single: false
 
 Any object can be tested for truth value, for use in an :keyword:`if` or
-:keyword:`while` condition or as operand of the Boolean operations below. The
-following values are considered false:
+:keyword:`while` condition or as operand of the Boolean operations below.
 
-  .. index:: single: None (Built-in object)
-
-* ``None``
-
-  .. index:: single: False (Built-in object)
-
-* ``False``
-
-* zero of any numeric type, for example, ``0``, ``0.0``, ``0j``.
+.. index:: single: true
 
-* any empty sequence, for example, ``''``, ``()``, ``[]``.
+By default, an object is considered true unless its class defines either a
+:meth:`__bool__` method that returns ``False`` or a :meth:`__len__` method that
+returns zero, when called with the object. [1]_  Here are most of the built-in
+objects considered false:
 
-* any empty mapping, for example, ``{}``.
+  .. index::
+     single: None (Built-in object)
+     single: False (Built-in object)
 
-* instances of user-defined classes, if the class defines a :meth:`__bool__` or
-  :meth:`__len__` method, when that method returns the integer zero or
-  :class:`bool` value ``False``. [1]_
+* constants defined to be false: ``None`` and ``False``.
 
-.. index:: single: true
+* zero of any numeric type: ``0``, ``0.0``, ``0j``, ``Decimal(0)``,
+  ``Fraction(0, 1)``
 
-All other values are considered true --- so objects of many types are always
-true.
+* empty sequences and collections: ``''``, ``()``, ``[]``, ``{}``, ``set()``,
+  ``range(0)``
 
 .. index::
    operator: or
diff --git a/Misc/NEWS.d/next/Documentation/2017-07-29-14-55-50.bpo-30803.6hutqQ.rst b/Misc/NEWS.d/next/Documentation/2017-07-29-14-55-50.bpo-30803.6hutqQ.rst
new file mode 100644
index 00000000000..4699713ee6e
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2017-07-29-14-55-50.bpo-30803.6hutqQ.rst
@@ -0,0 +1 @@
+Clarify doc on truth value testing. Original patch by Peter Thomassen.



More information about the Python-checkins mailing list