From: Serhiy Storchaka Date: Sun, 23 Apr 2017 05:50:20 +0000 (+0300) Subject: [3.5] bpo-15718: Document the upper bound constrain on the __len__ return value.... X-Git-Tag: v3.5.4rc1~194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c358536fd5e40e8f29ee4f086588a82fccb25a09;p=thirdparty%2FPython%2Fcpython.git [3.5] bpo-15718: Document the upper bound constrain on the __len__ return value. (GH-1256) (#1260) (cherry picked from commit 85157cd) --- diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index cd28c147b279..0d108d727e7a 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1887,6 +1887,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) @@ -1897,6 +1905,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 ::