fix a bit of py3 compat with OneToOne, also tweaked the repr

This commit is contained in:
Mahmoud Hashemi 2017-08-19 19:21:43 -07:00
parent 71835c149d
commit 48c243ba77
1 changed files with 5 additions and 3 deletions

View File

@ -756,7 +756,7 @@ class OneToOne(dict):
if isinstance(dict_or_iterable, dict): if isinstance(dict_or_iterable, dict):
for val in dict_or_iterable.values(): for val in dict_or_iterable.values():
hash(val) hash(val)
keys_vals = dict_or_iterable.items() keys_vals = list(dict_or_iterable.items())
else: else:
for key, val in dict_or_iterable: for key, val in dict_or_iterable:
hash(key) hash(key)
@ -764,11 +764,13 @@ class OneToOne(dict):
keys_vals = list(dict_or_iterable) keys_vals = list(dict_or_iterable)
for val in kw.values(): for val in kw.values():
hash(val) hash(val)
keys_vals += kw.items() keys_vals.extend(kw.items())
for key, val in keys_vals: for key, val in keys_vals:
self[key] = val self[key] = val
def __repr__(self): def __repr__(self):
return "OneToOne(" + dict.__repr__(self) + ")" cn = self.__class__.__name__
dict_repr = dict.__repr__(self)
return "%s(%s)" % (cn, dict_repr)
# end dictutils.py # end dictutils.py