[pypy-commit] pypy py3.5: With the dict unpacking syntax {1:2, **dict, 3:4} ast.Dict.keys can contain null values.
amauryfa
pypy.commits at gmail.com
Sat Oct 1 15:11:05 EDT 2016
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.5
Changeset: r87502:a45e290ae6ee
Date: 2016-10-01 21:10 +0200
http://bitbucket.org/pypy/pypy/changeset/a45e290ae6ee/
Log: With the dict unpacking syntax {1:2, **dict, 3:4} ast.Dict.keys can
contain null values. Fix a segfault in test_ast.
diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -1963,7 +1963,7 @@
if self.keys is None:
keys_w = []
else:
- keys_w = [node.to_object(space) for node in self.keys] # expr
+ keys_w = [node.to_object(space) if node is not None else space.w_None for node in self.keys] # expr
w_keys = space.newlist(keys_w)
space.setattr(w_node, space.wrap('keys'), w_keys)
if self.values is None:
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -136,9 +136,13 @@
return "space.wrap(%s)" % (value,)
else:
wrapper = "%s.to_object(space)" % (value,)
- # XXX: kw_defaults, unlike other sequences, allows None
- # values
- if field.opt or field.name == 'kw_defaults':
+ allow_none = field.opt
+ # Some sequences allow None values:
+ # - arguments.kw_defaults (for mandatory kw-only arguments)
+ # - Dict.keys (for **nested_dict elements)
+ if field.name in ('kw_defaults', 'keys'):
+ allow_none = True
+ if allow_none:
wrapper += " if %s is not None else space.w_None" % (value,)
return wrapper
diff --git a/pypy/module/_ast/test/test_ast.py b/pypy/module/_ast/test/test_ast.py
--- a/pypy/module/_ast/test/test_ast.py
+++ b/pypy/module/_ast/test/test_ast.py
@@ -478,3 +478,6 @@
comp = ast.Compare(left, [ast.In()], [ast.Num("blah")])
_expr(comp, "non-numeric", exc=TypeError)
+ def test_dict_unpacking(self):
+ self.get_ast("{**{1:2}, 2:3}")
+
More information about the pypy-commit
mailing list