diff --git a/multidict/_multidict_py.py b/multidict/_multidict_py.py index f9c8f384a..bff82767a 100644 --- a/multidict/_multidict_py.py +++ b/multidict/_multidict_py.py @@ -185,12 +185,13 @@ def _extend(self, args, kwargs, name, method): elif hasattr(arg, 'items'): items = arg.items() else: + items = [] for item in arg: if not len(item) == 2: raise TypeError( "{} takes either dict or list of (key, value) " "tuples".format(name)) - items = arg + items.append(item) for key, value in items: method(key, value) diff --git a/tests/test_multidict.py b/tests/test_multidict.py index 8fa6e785e..268a26e95 100644 --- a/tests/test_multidict.py +++ b/tests/test_multidict.py @@ -73,6 +73,15 @@ def test_instantiate__with_kwargs(self): self.assertEqual(sorted(d.items()), [('key', 'value1'), ('key2', 'value2')]) + def test_instantiate__from_generator(self): + d = self.make_dict((str(i), i) for i in range(2)) + + self.assertEqual(d, {'0': 0, '1': 1}) + self.assertEqual(len(d), 2) + self.assertEqual(sorted(d.keys()), ['0', '1']) + self.assertEqual(sorted(d.values()), [0, 1]) + self.assertEqual(sorted(d.items()), [('0', 0), ('1', 1)]) + def test_getone(self): d = self.make_dict([('key', 'value1')], key='value2') self.assertEqual(d.getone('key'), 'value1')