Message347949
Thanks Elizabeth for the test. The regression test seems to be same as the case noted by Serhiy that Foo.__eq__ is not returning NotImplemented so that ANY.__eq__ can be executed. Below would be the correct implementation that passes.
The actual comparison is done at [0]. If Foo.__eq__ returned NotImplemented due to type difference it would have called other.arguments. So there is no chance for ANY.__eq__ to be executed. I feel it's more about the third party class that needs to be fixed rather than the stdlib code here and changing the order of arguments for ANY's __eq__ precedence might introduce other subtle bugs.
self.arguments = OrderedDict([('args', (<__main__.Foo object at 0x10a54b500>,))])
other.arguments = OrderedDict([('args', (<ANY>,))])
def __eq__(self, other):
if self is other:
return True
if not isinstance(other, BoundArguments):
return NotImplemented
return (self.signature == other.signature and
self.arguments == other.arguments)
# Better implementation
from unittest.mock import Mock, call, ANY
class Foo(object):
def __eq__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
return True
def __ne__(self, other): pass
mock = Mock(spec_set=Foo)
expected = [call(ANY)]
mock(Foo())
mock.assert_has_calls(expected)
[0] https://github.com/python/cpython/blob/cd6e83b4810549c308ab2d7315dbab526e35ccf6/Lib/inspect.py#L2708
3.5 and 3.6 are in security fixes only mode. If this is considered to be a bug it can go in master, 3.8 and 3.7. The tests section is for CPython test suite and not for the unittest related bugs. So triaging it back. |
|
Date |
User |
Action |
Args |
2019-07-15 05:40:17 | xtreak | set | recipients:
+ xtreak, serhiy.storchaka, ElizabethU |
2019-07-15 05:40:17 | xtreak | set | messageid: <1563169217.46.0.496585452564.issue37555@roundup.psfhosted.org> |
2019-07-15 05:40:17 | xtreak | link | issue37555 messages |
2019-07-15 05:40:17 | xtreak | create | |
|