New submission from Anthony Foglia <afog...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue6324>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to