Karthikeyan Singaravelan <[email protected]> added the comment:
Thanks for the report. Can you please add an example without Django or other
dependencies so that I can try reproducing it? I am trying out the below
program from the report where Foo has overridden __eq__ to return False if the
other object being compared is not a Foo object. In the next statements ANY ==
Foo() returns True since the left side's object.__eq__ is used which in this
case is ANY.__eq__ as you have noted in the original report.
When list of call objects are compared there is also a code comment about this
in the tuple comparison of args and kwargs such that ANY is placed on the left
side [0] so that ANY.__eq__ is used. A pure python example and traceback if any
would help here.
from unittest.mock import call, ANY, Mock
class Foo:
def __eq__(self, other):
if not isinstance(other, Foo):
return False
return True
m = Mock()
obj = Foo()
m(obj, 1)
m.assert_has_calls([call(ANY, 1)])
print(ANY == Foo()) # ANY.__eq__ is called
print(Foo() == ANY) # Foo().__eq__ is called
Is the report more about the below case where position of call objects returns
different values?
print(call(ANY, 1) == call(obj, 1)) # False
print(call(obj, 1) == call(ANY, 1)) # True
[0]
https://github.com/python/cpython/blob/2a3d4d9c53dd4831c3ecf56bc7c4a289c33030d6/Lib/unittest/mock.py#L2407
----------
components: +Library (Lib) -Tests
nosy: +xtreak
versions: -Python 3.5, Python 3.6
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37555>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com