From 5bfdf971d91168f0ccab8fccce4ad247eb2081ad Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 22 Apr 2017 18:00:58 +0300 Subject: [PATCH 1/3] bpo-15718: Document the upper bound constrain on __len__ return value. --- Doc/reference/datamodel.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 095a2380b379bc9..fa52d3fb6e2be9b 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -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 ``sys.maxsize`` some features (such as + :func:`len`) may raise :exc:`OverflowError`. To prevent raising + ``OverflowError`` by truth value testing an object must define a + :meth:`__bool__` method. + .. method:: object.__length_hint__(self) @@ -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 :: From 96c9414fffbc1d59867a700ece459c73785a92be Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 22 Apr 2017 19:23:54 +0300 Subject: [PATCH 2/3] Add missed comma. --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index fa52d3fb6e2be9b..cd7978a850e3fd0 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2016,7 +2016,7 @@ through the container; for mappings, :meth:`__iter__` should be the same as In CPython, the length is required to be at most :attr:`sys.maxsize`. If the length is larger than ``sys.maxsize`` some features (such as :func:`len`) may raise :exc:`OverflowError`. To prevent raising - ``OverflowError`` by truth value testing an object must define a + ``OverflowError`` by truth value testing, an object must define a :meth:`__bool__` method. From 88b6e937a3522a50dae82818284b4bdec2cd5d4c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 23 Apr 2017 08:28:41 +0300 Subject: [PATCH 3/3] Ad an indent and update the formatting. --- Doc/reference/datamodel.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index cd7978a850e3fd0..35925a065fd495b 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2011,13 +2011,13 @@ 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:: + .. impl-detail:: - In CPython, the length is required to be at most :attr:`sys.maxsize`. - If the length is larger than ``sys.maxsize`` some features (such as - :func:`len`) may raise :exc:`OverflowError`. To prevent raising - ``OverflowError`` by truth value testing, an object must define a - :meth:`__bool__` method. + 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)