Skip to content

bpo-15718: Document the upper bound constrain on __len__ return value. #1256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 ::
Expand Down