25.01.20 00:29, Tim Peters пише:
I think it needs more words, though, to flesh out what about this is
allowed by the language (as opposed to what CPython happens to do),
and to get closer to what Guido is trying to get at with his
"*implicit* calls". For example, it's at work here, but there's not a
built-in container in sight:
import math
def f():
... while True:
... yield math.nan
math.nan in f()
True
It is documented in:
https://docs.python.org/3/reference/expressions.html#membership-test-operations
"""
For user-defined classes which do not define :meth:`__contains__` but do
define
:meth:`__iter__`, ``x in y`` is ``True`` if some value ``z``, for which the
expression ``x is z or x == z`` is true, is produced while iterating
over ``y``.
If an exception is raised during the iteration, it is as if
:keyword:`in` raised
that exception.
Lastly, the old-style iteration protocol is tried: if a class defines
:meth:`__getitem__`, ``x in y`` is ``True`` if and only if there is a
non-negative
integer index *i* such that ``x is y[i] or x == y[i]``, and no lower
integer index
raises the :exc:`IndexError` exception. (If any other exception is
raised, it is as
if :keyword:`in` raised that exception).
"""
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/44IJUXAKFTF7VS3D4G4IFWJA2LPK23KL/
Code of Conduct: http://python.org/psf/codeofconduct/