From: Serhiy Storchaka Date: Sun, 23 Apr 2017 05:58:09 +0000 (+0300) Subject: [2.7] bpo-15718: Document the upper bound constrain on the __len__ return value.... X-Git-Tag: v2.7.14rc1~201 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfc7dff63b9b30371e3423a5c35ccda2f3b52218;p=thirdparty%2FPython%2Fcpython.git [2.7] bpo-15718: Document the upper bound constrain on the __len__ return value. (GH-1256). (#1261) (cherry picked from commit 85157cd89a6edac347a5b6871fcf20c500c6fbbf) --- diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 4adf5fa59fdf..7bdb141ae55e 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1891,6 +1891,14 @@ sequences, it should iterate through the values. :meth:`__nonzero__` 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:`__nonzero__` method. + .. method:: object.__getitem__(self, key)