[docs] [issue16011] "in" should be consistent with return value of __contains__

Ezio Melotti report at bugs.python.org
Mon Sep 24 07:42:21 CEST 2012


Ezio Melotti added the comment:

http://docs.python.org/py3k/reference/datamodel.html#object.__contains__ says that __contain__ "Should return true if item is in self, false otherwise.".  Here the lowercase true and false mean any true or false value, not just True and False and it's indeed possible to return any value.

The fact that 'in' only returns True/False, possibly converting the return value of __contains__, should be documented in the 'in' documentation.
http://docs.python.org/py3k/reference/expressions.html#membership-test-details says "For user-defined classes which define the __contains__() method, x in y is true if and only if y.__contains__(x) is true.".  This could be changed to say that the return value is converted to True/False.

----------
keywords: +easy
nosy: +ezio.melotti
stage:  -> needs patch
versions: +Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16011>
_______________________________________


More information about the docs mailing list