Skip to content

Commit 2f5b9dc

Browse files
ztanecsabella
authored andcommitted
bpo-30969: Fix docs about the comparison in absence of __contains__ (GH-2761)
1 parent 1e36f75 commit 2f5b9dc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Doc/reference/expressions.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,14 +1563,15 @@ y`` returns ``True`` if ``y.__contains__(x)`` returns a true value, and
15631563
``False`` otherwise.
15641564

15651565
For user-defined classes which do not define :meth:`__contains__` but do define
1566-
:meth:`__iter__`, ``x in y`` is ``True`` if some value ``z`` with ``x == z`` is
1567-
produced while iterating over ``y``. If an exception is raised during the
1568-
iteration, it is as if :keyword:`in` raised that exception.
1566+
:meth:`__iter__`, ``x in y`` is ``True`` if some value ``z``, for which the
1567+
expression ``x is z or x == z`` is true, is produced while iterating over ``y``.
1568+
If an exception is raised during the iteration, it is as if :keyword:`in` raised
1569+
that exception.
15691570

15701571
Lastly, the old-style iteration protocol is tried: if a class defines
15711572
:meth:`__getitem__`, ``x in y`` is ``True`` if and only if there is a non-negative
1572-
integer index *i* such that ``x == y[i]``, and all lower integer indices do not
1573-
raise :exc:`IndexError` exception. (If any other exception is raised, it is as
1573+
integer index *i* such that ``x is y[i] or x == y[i]``, and no lower integer index
1574+
raises the :exc:`IndexError` exception. (If any other exception is raised, it is as
15741575
if :keyword:`in` raised that exception).
15751576

15761577
.. index::

0 commit comments

Comments
 (0)