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 f069cde
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions six.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ def iterlists(d, **kw):

viewitems = operator.methodcaller("items")
else:
import collections as _collections

def iterkeys(d, **kw):
return d.iterkeys(**kw)

Expand All @@ -609,11 +611,27 @@ def iteritems(d, **kw):
def iterlists(d, **kw):
return d.iterlists(**kw)

viewkeys = operator.methodcaller("viewkeys")

viewvalues = operator.methodcaller("viewvalues")
def viewkeys(d):
return (
_collections.KeysView(d)
if isinstance(d, types.DictProxyType)
else d.viewkeys()
)

def viewvalues(d):
return (
_collections.ValuesView(d)
if isinstance(d, types.DictProxyType)
else d.viewvalues()
)

def viewitems(d):
return (
_collections.ItemsView(d)
if isinstance(d, types.DictProxyType)
else 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 f069cde

Please sign in to comment.