This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author afoglia
Recipients afoglia, georg.brandl, rhettinger, terry.reedy
Date 2009-10-22.06:20:09
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <1256192412.78.0.801116991702.issue6324@psf.upfronthosting.co.za>
In-reply-to
Content
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."
History
Date User Action Args
2009-10-22 06:20:12afogliasetrecipients: + afoglia, georg.brandl, rhettinger, terry.reedy
2009-10-22 06:20:12afogliasetmessageid: <1256192412.78.0.801116991702.issue6324@psf.upfronthosting.co.za>
2009-10-22 06:20:10afoglialinkissue6324 messages
2009-10-22 06:20:09afogliacreate