Skip to content

Commit c358536

Browse files
[3.5] bpo-15718: Document the upper bound constrain on the __len__ return value. (GH-1256) (#1260)
(cherry picked from commit 85157cd)
1 parent 7badde2 commit c358536

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Doc/reference/datamodel.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,14 @@ through the container; for mappings, :meth:`__iter__` should be the same as
18871887
:meth:`__bool__` method and whose :meth:`__len__` method returns zero is
18881888
considered to be false in a Boolean context.
18891889

1890+
.. impl-detail::
1891+
1892+
In CPython, the length is required to be at most :attr:`sys.maxsize`.
1893+
If the length is larger than :attr:`!sys.maxsize` some features (such as
1894+
:func:`len`) may raise :exc:`OverflowError`. To prevent raising
1895+
:exc:`!OverflowError` by truth value testing, an object must define a
1896+
:meth:`__bool__` method.
1897+
18901898

18911899
.. method:: object.__length_hint__(self)
18921900

@@ -1897,6 +1905,7 @@ through the container; for mappings, :meth:`__iter__` should be the same as
18971905

18981906
.. versionadded:: 3.4
18991907

1908+
19001909
.. note::
19011910

19021911
Slicing is done exclusively with the following three methods. A call like ::

0 commit comments

Comments
 (0)