[New-bugs-announce] [issue6324] "in" expression falls back to __iter__ before __getitem__
Anthony Foglia
report at bugs.python.org
Mon Jun 22 21:27:54 CEST 2009
New submission from Anthony Foglia <afoglia at gmail.com>:
I was debugging a class where I defined __getitem__ and __iter__, but
not __contains__. The documentation describing this case (at the end of
section 5.9) is old and hasn't been updated for the iterator protocol.
It should read something like:
"For user-defined classes which do not define __contains__() and do
define __iter__() or __getitem__(), x in y is true if and only if there
is a value z reachable from iter(y) before iter(y) throws a
StopIteration exception. (If any other exception is raised, it is as if
in raised that exception)."
Or something better worded.
(I'm using Python 2.5, but I really doubt things have changes in 2.6 or
2.7. I don't know enough about 3.0 to know either way.)
----------
assignee: georg.brandl
components: Documentation
messages: 89607
nosy: afoglia, georg.brandl
severity: normal
status: open
title: "in" expression falls back to __iter__ before __getitem__
versions: Python 2.5, Python 2.6, Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6324>
_______________________________________
More information about the New-bugs-announce
mailing list