multi_key_dict
multi_key_dict copied to clipboard
Unable to compare two multi_key_dict instances
In python you can compare two dictionaries but if you try to compare two multi_key_dict instances it will return False even when it should not.
#!/usr/bin/env python
from copy import copy
from multi_key_dict import multi_key_dict
k = multi_key_dict()
k['a', 'b'] = 1
print(k == copy(k))
b = {}
a = copy(b)
print(a == b)
The code above is supposed to return True for both cases but as you can probably see, it returns False for multi_key_dict.
This is a serious issue as it also affects pickling and mocking.
good point, it makes sense, thanks for pointing that out.
It should not be too hard to implement __eq__()
method, this should do the deal. I already have some code that I used to workaround this bug (may need improvement).
Btw, while playing with this class I observed that I am not able to do something like:
for k in multi_dict.keys():
print(multi_dict[k])
k
is a tuple and this throws an error, is this another bug of an implementation limitation? If it could be possible to make it behave more like a normal dictionary it would make easier to use it.