[issue38105] hash collision when hash(x) == -2 causes many calls to __eq__

Steven D'Aprano report at bugs.python.org
Wed Sep 11 07:00:14 EDT 2019


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Here's a possibly simpler version which nevertheless still shows multiple calls to __eq__ (in this case, only 6, not 13):

class C(object):
    def __eq__(self, other):
        print('eq')
        return super().__eq__(other)
    def __hash__(self):
        return -2

d = {-2, C()}



which outputs:
eq
eq
eq
eq
eq
eq

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38105>
_______________________________________


More information about the Python-bugs-list mailing list