Skip to content

Commit ed99bb9

Browse files
authored
bpo-37913: document that __length_hint__ can return NotImplemented (GH-15383)
1 parent 45bc392 commit ed99bb9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Doc/reference/datamodel.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,9 @@ through the container; for mappings, :meth:`__iter__` should be the same as
21552155

21562156
Called to implement :func:`operator.length_hint`. Should return an estimated
21572157
length for the object (which may be greater or less than the actual length).
2158-
The length must be an integer ``>=`` 0. This method is purely an
2158+
The length must be an integer ``>=`` 0. The return value may also be
2159+
:const:`NotImplemented`, which is treated the same as if the
2160+
``__length_hint__`` method didn't exist at all. This method is purely an
21592161
optimization and is never required for correctness.
21602162

21612163
.. versionadded:: 3.4

0 commit comments

Comments
 (0)