[pypy-commit] pypy virtual-arguments: it still makes sense to make it possible to view a stringdict as a kwargs dict,
cfbolz
noreply at buildbot.pypy.org
Mon Apr 16 11:46:46 CEST 2012
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: virtual-arguments
Changeset: r54405:f996e07586bc
Date: 2012-04-14 13:19 +0200
http://bitbucket.org/pypy/pypy/changeset/f996e07586bc/
Log: it still makes sense to make it possible to view a stringdict as a
kwargs dict, because the unrolling is much more efficient than going
through the generic space.unpackiterable.
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -508,6 +508,13 @@
def w_keys(self, w_dict):
return self.space.newlist_str(self.listview_str(w_dict))
+ def view_as_kwargs(self, w_dict):
+ d = self.unerase(w_dict.dstorage)
+ keys, values = [], []
+ for key, val in d.iteritems():
+ keys.append(key)
+ values.append(val)
+ return keys, values
class _WrappedIteratorMixin(object):
_mixin_ = True
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -1108,6 +1108,10 @@
assert self.impl.getitem(s) == 1000
assert s.unwrapped
+ def test_view_as_kwargs(self):
+ self.fill_impl()
+ assert self.fakespace.view_as_kwargs(self.impl) == (["fish", "fish2"], [1000, 2000])
+
## class TestMeasuringDictImplementation(BaseTestRDictImplementation):
## ImplementionClass = MeasuringDictImplementation
## DevolvedClass = MeasuringDictImplementation
More information about the pypy-commit
mailing list