multi_key_dict icon indicating copy to clipboard operation
multi_key_dict copied to clipboard

Unable to compare two multi_key_dict instances

Open ssbarnea opened this issue 8 years ago • 3 comments

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.

ssbarnea avatar Dec 21 '16 21:12 ssbarnea

good point, it makes sense, thanks for pointing that out.

formiaczek avatar Dec 22 '16 15:12 formiaczek

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).

ssbarnea avatar Dec 22 '16 16:12 ssbarnea

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.

ssbarnea avatar Dec 22 '16 16:12 ssbarnea