From a7edd8da7e5375a6495a1413078ec55d7c3d6341 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 12 Aug 2019 11:51:19 +0100 Subject: [PATCH] workaround missing dictproxy methods Fixes #295 --- six.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/six.py b/six.py index 4c303ff97..6c87d8005 100644 --- a/six.py +++ b/six.py @@ -607,11 +607,21 @@ def iteritems(d, **kw): def iterlists(d, **kw): return d.iterlists(**kw) - viewkeys = operator.methodcaller("viewkeys") + def viewkeys(d): + if isinstance(d, types.DictProxyType): + d = dict(d) + return d.viewkeys() - viewvalues = operator.methodcaller("viewvalues") + def viewvalues(d): + if isinstance(d, types.DictProxyType): + d = dict(d) + return d.viewvalues() + + def viewitems(d): + if isinstance(d, types.DictProxyType): + d = dict(d) + return d.viewitems() - viewitems = operator.methodcaller("viewitems") _add_doc(iterkeys, "Return an iterator over the keys of a dictionary.") _add_doc(itervalues, "Return an iterator over the values of a dictionary.")