Raymond Hettinger <[email protected]> added the comment:
> The code in msg311969 doesn't reuse hash values.
That doesn't make sense. The dict.update() method reuses the hashes of the
input mappings when possible.
>>> from collections import ChainMap
>>> class Int(int):
def __hash__(self):
print(f'Hashing {self}', file=sys.stderr)
return int.__hash__(self)
>>> import sys
>>> d = { Int(1): 'f1', Int(2): 'f2' }
Hashing 1
Hashing 2
>>> e = { Int(1): 's1', Int(3): 's3' }
Hashing 1
Hashing 3
>>> c = ChainMap(d, e)
>>> list(c) # Note, no calls to hash() were made
[1, 3, 2]
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32792>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com