fixed a bug in __setitem__

This commit is contained in:
Lukasz Forynski 2013-09-01 02:56:38 +01:00
parent cc79d66879
commit 07dff2e2ba
3 changed files with 19 additions and 8 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
*.pyc
*.exe
*/dist/*
MANIFEST

View File

@ -76,21 +76,22 @@ class multi_key_dict(object):
num_of_keys_we_have = reduce(lambda x, y: x+y, map(lambda x : self.has_key(x), keys))
if num_of_keys_we_have:
all_select_same_item = True
direct_key = None
for key in keys:
direct_key = None
key_type = str(type(key))
try:
if direct_key is None:
direct_key = self.items_dict[key]
if not direct_key:
direct_key = self.__dict__[key_type][key]
else:
new = self.items_dict[key]
new = self.__dict__[key_type][key]
if new != direct_key:
all_select_same_item = False
break
except:
except Exception, err:
all_select_same_item = False
break;
if num_of_keys_we_have < len(keys) and not all_select_same_item:
if num_of_keys_we_have <= len(keys) and not all_select_same_item:
raise KeyError(', '.join(str(key) for key in keys))
first_key = keys[0] # combination if keys is allowed, simply use the first one
@ -488,6 +489,14 @@ def test_multi_key_dict():
except KeyError, err:
pass
# test setitem with multiple keys
m['cd'] = 'somethingelse'
try:
m['cd', 999] = 'otherstr'
assert(False), 'creating / updating m[\'cd\', 999] should fail!'
except KeyError, err:
pass
m['xy', 999] = 'otherstr'
assert (m['xy'] == 'otherstr'), 'm[\'xy\'] is not as expected.'
assert (m[999] == 'otherstr'), 'm[999] is not as expected.'

View File

@ -8,7 +8,7 @@ with open('README.txt') as readme:
long_descr = readme.read()
setup(name='multi_key_dict',
version='1.0.3',
version='1.0.4',
description='Multi key dictionary implementation',
author='Lukasz Forynski',
author_email='lukasz.forynski@gmail.com',