Author: Carl Friedrich Bolz <[email protected]>
Branch: kwargsdict-strategy
Changeset: r54227:0cfe5878d642
Date: 2012-04-05 23:22 +0200
http://bitbucket.org/pypy/pypy/changeset/0cfe5878d642/
Log: make a kwargs dict when calling a function that takes **args
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -385,7 +385,7 @@
# collect extra keyword arguments into the **kwarg
if has_kwarg:
- w_kwds = self.space.newdict()
+ w_kwds = self.space.newdict(kwargs=True)
if num_remainingkwds:
#
limit = len(keywords)
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -110,7 +110,7 @@
"NOT_RPYTHON"
raise NotImplementedError
- def newdict(self, module=False, instance=False,
+ def newdict(self, module=False, instance=False, kwargs=False,
strdict=False):
return w_some_obj()
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
@@ -33,7 +33,7 @@
@staticmethod
def allocate_and_init_instance(space, w_type=None, module=False,
- instance=False, strdict=False):
+ instance=False, strdict=False,
kwargs=False):
if space.config.objspace.std.withcelldict and module:
from pypy.objspace.std.celldict import ModuleDictStrategy
@@ -46,11 +46,15 @@
assert w_type is None
strategy = space.fromcache(StringDictStrategy)
+ elif kwargs:
+ assert w_type is None
+ from pypy.objspace.std.kwargsdict import KwargsDictStrategy
+ strategy = space.fromcache(KwargsDictStrategy)
else:
strategy = space.fromcache(EmptyDictStrategy)
-
if w_type is None:
w_type = space.w_dict
+
storage = strategy.get_empty_storage()
w_self = space.allocate_instance(W_DictMultiObject, w_type)
W_DictMultiObject.__init__(w_self, space, strategy, storage)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -313,11 +313,11 @@
def newlist_str(self, list_s):
return W_ListObject.newlist_str(self, list_s)
- def newdict(self, module=False, instance=False,
+ def newdict(self, module=False, instance=False, kwargs=False,
strdict=False):
return W_DictMultiObject.allocate_and_init_instance(
self, module=module, instance=instance,
- strdict=strdict)
+ strdict=strdict, kwargs=kwargs)
def newset(self):
from pypy.objspace.std.setobject import newset
diff --git a/pypy/objspace/std/test/test_kwargsdict.py
b/pypy/objspace/std/test/test_kwargsdict.py
--- a/pypy/objspace/std/test/test_kwargsdict.py
+++ b/pypy/objspace/std/test/test_kwargsdict.py
@@ -82,3 +82,20 @@
get_impl = get_impl
StrategyClass = KwargsDictStrategy
+
+class AppTestKwargsDictStrategy(object):
+ def setup_class(cls):
+ if option.runappdirect:
+ py.test.skip("__repr__ doesn't work on appdirect")
+
+ def w_get_strategy(self, obj):
+ import __pypy__
+ r = __pypy__.internal_repr(obj)
+ return r[r.find("(") + 1: r.find(")")]
+
+ def test_create(self):
+ def f(**args):
+ return args
+ d = f(a=1)
+ assert "KwargsDictStrategy" in self.get_strategy(d)
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit