Skip to content

Commit bfc7dff

Browse files
[2.7] bpo-15718: Document the upper bound constrain on the __len__ return value. (GH-1256). (#1261)
(cherry picked from commit 85157cd)
1 parent 91e5ee5 commit bfc7dff

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/reference/datamodel.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,14 @@ sequences, it should iterate through the values.
18911891
:meth:`__nonzero__` method and whose :meth:`__len__` method returns zero is
18921892
considered to be false in a Boolean context.
18931893

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

18951903
.. method:: object.__getitem__(self, key)
18961904

0 commit comments

Comments
 (0)