Steven D'Aprano added the comment:

I'm reluctant to call this a behaviour bug, because I'm reluctant to guarantee 
the *precise* behaviour when the classes are different.

I haven't checked the source of dict.__contains__, but by experimentation it 
seems that:

    needle in {key: value}

calls key == needle, rather than needle == key as the docs would imply. This 
seems to apply going all the way back to at least CPython2.4.

On the other hand, Jython2.5 and IronPython2.6 seem to call needle == key as 
Vasily expected.

But the docs are clearly incomplete, as they suggest a linear search through 
all the keys of the dict (or set), which is wrong. Only if needle hashes to the 
same value as key will == be called.

I suggest updating the docs to make it clear that the sample code shown is only 
the *approximate* behaviour, which may call == in either direction.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27605>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to