-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Description
PMap.__getitem__
will return the wrong value if the object used for the key defines a unique __hash__
and a custom __eq__
method.
Repro (tested with python 3.8 and pyrsistent 0.17.3):
from pyrsistent import pmap
class CustomObject(object):
__slots__ = ()
def __hash__(self):
return object.__hash__(self)
def __eq__(self, other): # Having __eq__ declared causes the failure
return True # Changing this to False will fail with a different error
keys = []
py_dict = {}
for i in range(10000):
key = CustomObject()
keys.append(key)
py_dict[key] = i
p_map = pmap(py_dict)
assert len(py_dict) == len(p_map)
assert set(py_dict.keys()) == set(p_map.keys())
for i, key in enumerate(keys):
assert py_dict[key] == i
assert p_map[key] == i # Fails here when `i` is a big number, __getitem__ gets the wrong value
Metadata
Metadata
Assignees
Labels
No labels