Skip to content

Commit

Permalink
workaround missing dictproxy methods Fixes benjaminp#295
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Nov 14, 2019
1 parent 4309e80 commit a27cb14
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions six.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,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.")
Expand Down

0 comments on commit a27cb14

Please sign in to comment.