Anthony Foglia <afog...@gmail.com> added the comment:

I've added Python 2.7 to the list of versions.  The development docs
have the same issue.

Let me try another stab at what the docs should say.  Following the
suggestion to add it to 3.3.5, perhaps it should be:

"
object.__contains__(self, item)
    Called to implement membership test operators. Should return true if
item is in self, false otherwise. For mapping objects, this should
consider the keys of the mapping rather than the values or the key-item
pairs.

    If __contains__ is not provided but __iter__ is provided, the
membership test "x in y" is true if and only if there is a value z
reachable by iterating iter(y) before iter(y) throws a StopIteration
exception.  (If any other exception is raised, it is as if
in raised that exception).

    If neither __contains__ nor __iter__ are provided but __getitem__ is
provided, the membership test "x in y" is true if and only if there is a
non-negative integer index i such that x == y[i], and all lower integer
indices do not raise IndexError exception. (If any other exception is
raised, it is as if in raised that exception).
"

I worry that this is becoming more a description of "in" rather than
__contains__. 

Either way, the last sentence in paragraph 6 of section 5.9 should refer
not just to 3.3.1 (Basic Customization) but also 3.3.5 (Emulating
Container Types).  The latter is where __contains__, __iter__ and
__getitem__ are defined.  Perhaps the new wording should be, "You can
control comparison behavior of objects of non-built-in types by defining
rich comparison methods like __gt__(), described in section Basic
customization, and the membership test method __contains__(), described
in section Emulating container types."

----------
versions: +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