[pypy-commit] pypy default: Merged in unpacking-cpython-shortcut (pull request #443)

arigo pypy.commits at gmail.com
Fri May 6 04:23:45 EDT 2016


Author: Armin Rigo <armin.rigo at gmail.com>
Branch: 
Changeset: r84256:e98228f40d1f
Date: 2016-05-06 10:23 +0200
http://bitbucket.org/pypy/pypy/changeset/e98228f40d1f/

Log:	Merged in unpacking-cpython-shortcut (pull request #443)

	Copy CPython's 'optimization': ignore __iter__ etc. for
	f(**dict_subclass())

diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -688,3 +688,21 @@
         def f(x): pass
         e = raises(TypeError, "f(**{u'ü' : 19})")
         assert "?" in str(e.value)
+
+    def test_starstarargs_dict_subclass(self):
+        def f(**kwargs):
+            return kwargs
+        class DictSubclass(dict):
+            def __iter__(self):
+                yield 'x'
+        # CPython, as an optimization, looks directly into dict internals when
+        # passing one via **kwargs.
+        x =DictSubclass()
+        assert f(**x) == {}
+        x['a'] = 1
+        assert f(**x) == {'a': 1}
+
+    def test_starstarargs_module_dict(self):
+        def f(**kwargs):
+            return kwargs
+        assert f(**globals()) == globals()
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
@@ -483,7 +483,7 @@
         return None
 
     def view_as_kwargs(self, w_dict):
-        if type(w_dict) is W_DictObject:
+        if isinstance(w_dict, W_DictObject):
             return w_dict.view_as_kwargs()
         return (None, None)
 


More information about the pypy-commit mailing list