Skip to content

Commit e8661c1

Browse files
bpo-30969: Fix docs about the comparison in absence of __contains__ (GH-2761)
(cherry picked from commit 2f5b9dc) Co-authored-by: Antti Haapala <[email protected]>
1 parent f1487b3 commit e8661c1

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
@@ -1568,14 +1568,15 @@ y`` returns ``True`` if ``y.__contains__(x)`` returns a true value, and
15681568
``False`` otherwise.
15691569

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

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

15811582
.. index::

0 commit comments

Comments
 (0)