Author steven.daprano
Recipients steven.daprano, vfaronov
Date 2016-07-24.14:23:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1469370208.64.0.810999982094.issue27605@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-07-24 14:23:28steven.dapranosetrecipients: + steven.daprano, vfaronov
2016-07-24 14:23:28steven.dapranosetmessageid: <1469370208.64.0.810999982094.issue27605@psf.upfronthosting.co.za>
2016-07-24 14:23:28steven.dapranolinkissue27605 messages
2016-07-24 14:23:28steven.dapranocreate