From 3555d46a9f2b90684962336b4f44e29180e38fdd Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 17 Sep 2017 10:19:10 +0300 Subject: [PATCH] Fix multidict construction --- CHANGES.rst | 2 +- multidict/_multidict.pyx | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index bb414d8ec..46a01029c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -3.2.0 (2017-09-16) +3.2.0 (2017-09-xx) ------------------ * Fix pickling (#134) diff --git a/multidict/_multidict.pyx b/multidict/_multidict.pyx index 6d5fe9cb2..16f32ef3c 100644 --- a/multidict/_multidict.pyx +++ b/multidict/_multidict.pyx @@ -293,9 +293,7 @@ cdef class MultiDict(_Base): if args: arg = args[0] - if isinstance(arg, CIMultiDict): - self._impl._items.extend((<_Base>arg)._impl._items) - elif isinstance(arg, _Base): + if isinstance(arg, _Base): for i in (<_Base>arg)._impl._items: item = <_Pair>i key = item._key @@ -387,8 +385,9 @@ cdef class MultiDict(_Base): def copy(self): """Return a copy of itself.""" - cls = self.__class__ - return cls(self) + ret = MultiDict() + ret._extend((list(self.items()),), {}, 'copy', True) + return ret def extend(self, *args, **kwargs): """Extend current MultiDict with more values. @@ -528,7 +527,6 @@ cdef class CIMultiDict(MultiDict): def __init__(self, *args, **kwargs): self._impl = _Impl() - self._extend(args, kwargs, 'CIMultiDict', True) def __reduce__(self): @@ -545,6 +543,13 @@ cdef class CIMultiDict(MultiDict): return PyObject_Str(s) return s.title() + def copy(self): + """Return a copy of itself.""" + ret = CIMultiDict() + ret._extend((list(self.items()),), {}, 'copy', True) + return ret + + abc.MutableMapping.register(CIMultiDict)