Author xtreak
Recipients ElizabethU, serhiy.storchaka, xtreak
Date 2019-07-15.05:40:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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)]



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:17xtreaksetrecipients: + xtreak, serhiy.storchaka, ElizabethU
2019-07-15 05:40:17xtreaksetmessageid: <>
2019-07-15 05:40:17xtreaklinkissue37555 messages
2019-07-15 05:40:17xtreakcreate