Skip to content

Commit 7ed02b1

Browse files
committed
Fix pure python multidict.extend() version
1 parent 84d1a8c commit 7ed02b1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

aiohttp/multidict.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,20 @@ def _extend(self, args, kwargs, name, method):
178178
raise TypeError("{} takes at most 1 positional argument"
179179
" ({} given)".format(name, len(args)))
180180
if args:
181+
arg = args[0]
181182
if isinstance(args[0], _MultiDictProxy):
182-
items = args[0].items()
183+
items = arg._items
183184
elif isinstance(args[0], _MultiDict):
184-
items = args[0].items()
185-
elif hasattr(args[0], 'items'):
186-
items = args[0].items()
185+
items = arg._items
186+
elif hasattr(arg, 'items'):
187+
items = arg.items()
187188
else:
188-
items = args[0]
189+
for item in arg:
190+
if not len(item) == 2:
191+
raise TypeError(
192+
"{} takes either dict or list of (key, value) "
193+
"tuples".format(name))
194+
items = arg
189195

190196
for key, value in items:
191197
method(key, value)

tests/test_multidict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def test_extend_with_upstr(self):
290290
us = self.upstr_cls('a')
291291
d = self.make_dict()
292292

293-
d.extend((us, 'val'))
293+
d.extend([(us, 'val')])
294294
self.assertEqual([('A', 'val')], list(d.items()))
295295

296296

0 commit comments

Comments
 (0)