Skip to content

Commit 85157cd

Browse files
bpo-15718: Document the upper bound constrain on the __len__ return value. (python#1256)
1 parent 997a4ad commit 85157cd

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
@@ -2011,6 +2011,14 @@ through the container; for mappings, :meth:`__iter__` should be the same as
20112011
:meth:`__bool__` method and whose :meth:`__len__` method returns zero is
20122012
considered to be false in a Boolean context.
20132013

2014+
.. impl-detail::
2015+
2016+
In CPython, the length is required to be at most :attr:`sys.maxsize`.
2017+
If the length is larger than :attr:`!sys.maxsize` some features (such as
2018+
:func:`len`) may raise :exc:`OverflowError`. To prevent raising
2019+
:exc:`!OverflowError` by truth value testing, an object must define a
2020+
:meth:`__bool__` method.
2021+
20142022

20152023
.. method:: object.__length_hint__(self)
20162024

@@ -2021,6 +2029,7 @@ through the container; for mappings, :meth:`__iter__` should be the same as
20212029

20222030
.. versionadded:: 3.4
20232031

2032+
20242033
.. note::
20252034

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

0 commit comments

Comments
 (0)