summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-23 05:50:14 (GMT)
committerGitHub <noreply@github.com>2017-04-23 05:50:14 (GMT)
commitf2ed2858eea7569c8915b3611ca5ec92ae10b17f (patch)
tree80a95efec914b0f0d770d7568a18657b298478b5
parent9d022f169ec64987b29359ae0e904026aab07a64 (diff)
downloadcpython-f2ed2858eea7569c8915b3611ca5ec92ae10b17f.zip
cpython-f2ed2858eea7569c8915b3611ca5ec92ae10b17f.tar.gz
cpython-f2ed2858eea7569c8915b3611ca5ec92ae10b17f.tar.bz2
[3.6] bpo-15718: Document the upper bound constrain on the __len__ return value. (GH-1256) (#1259)
(cherry picked from commit 85157cd)
-rw-r--r--Doc/reference/datamodel.rst9
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 095a238..35925a0 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -2011,6 +2011,14 @@ through the container; for mappings, :meth:`__iter__` should be the same as
:meth:`__bool__` method and whose :meth:`__len__` method returns zero is
considered to be false in a Boolean context.
+ .. impl-detail::
+
+ In CPython, the length is required to be at most :attr:`sys.maxsize`.
+ If the length is larger than :attr:`!sys.maxsize` some features (such as
+ :func:`len`) may raise :exc:`OverflowError`. To prevent raising
+ :exc:`!OverflowError` by truth value testing, an object must define a
+ :meth:`__bool__` method.
+
.. method:: object.__length_hint__(self)
@@ -2021,6 +2029,7 @@ through the container; for mappings, :meth:`__iter__` should be the same as
.. versionadded:: 3.4
+
.. note::
Slicing is done exclusively with the following three methods. A call like ::