]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-37555: Fix _CallList and _Call order sensitivity
authorElizabeth Uselton <elizabeth.uselton@rover.com>
Thu, 18 Jul 2019 06:28:50 +0000 (23:28 -0700)
committerElizabeth Uselton <elizabeth.uselton@rover.com>
Thu, 18 Jul 2019 06:28:50 +0000 (23:28 -0700)
commit874fb697b8376fcea130116e56189061f944fde6
tree768897751a615e812effe3c8e730ec2f1dce77b4
parent49c5310ad493c4356dd3bc58c03653cd9466c4fa
bpo-37555: Fix _CallList and _Call order sensitivity

_Call and _CallList depend on ordering to correctly process that an object being compared to ANY with __eq__ should return True. This fix updates the comparison to check both a == b and b == a and return True if either condition is met, fixing situations from the tests in the previous two commits where assertEqual would not be commutative if checking _Call or _CallList objects. This seems like a reasonable fix considering that the Python data model specifies that if an object doesn't know how to compare itself to another object it should return NotImplemented, and that on getting NotImplemented from a == b, it should try b == a, implying that good behavior for __eq__ is commutative. This also flips the order of comparison in _CallList's __contains__ method, guaranteeing ANY will be on the left and have it's __eq__ called for equality checking, fixing the interaction between assert_has_calls and ANY.

Co-author: Neal Finne <neal@neal.finne.com>
Lib/unittest/mock.py