diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-09-02 19:50:04 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-09-02 19:50:04 (GMT) |
commit | 1fa3652e59b5060d9c17671b24f8f92ec2a85326 (patch) | |
tree | 840fb19b8573d9950ee7462834077ad2b9eb7515 | |
parent | 177b8eb34fed9a299ad00cea8e8be45fd836ab91 (diff) | |
parent | 2051b84f44a295e6668054e56db637a07e962698 (diff) | |
download | cpython-1fa3652e59b5060d9c17671b24f8f92ec2a85326.zip cpython-1fa3652e59b5060d9c17671b24f8f92ec2a85326.tar.gz cpython-1fa3652e59b5060d9c17671b24f8f92ec2a85326.tar.bz2 |
Merge 3.5 (issue #24975)
-rw-r--r-- | Lib/test/test_ast.py | 24 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Python/ast.c | 6 |
3 files changed, 21 insertions, 11 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 7ed03e7..f1c655b 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -78,9 +78,9 @@ exec_tests = [ # Pass, "pass", # Break - "break", + "for v in v:break", # Continue - "continue", + "for v in v:continue", # for statements with naked tuples (see http://bugs.python.org/issue6704) "for a,b in c: pass", "[(a,b) for a,b in c]", @@ -112,6 +112,9 @@ exec_tests = [ "async def f():\n async for e in i: 1\n else: 2", # AsyncWith "async def f():\n async with a as b: 1", + # PEP 448: Additional Unpacking Generalizations + "{**{1:2}, 2:3}", + "{*{1, 2}, 3}", ] # These are compiled through "single" @@ -231,9 +234,12 @@ class AST_Tests(unittest.TestCase): (single_tests, single_results, "single"), (eval_tests, eval_results, "eval")): for i, o in zip(input, output): - ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST) - self.assertEqual(to_tuple(ast_tree), o) - self._assertTrueorder(ast_tree, (0, 0)) + with self.subTest(action="parsing", input=i): + ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST) + self.assertEqual(to_tuple(ast_tree), o) + self._assertTrueorder(ast_tree, (0, 0)) + with self.subTest(action="compiling", input=i): + compile(ast_tree, "?", kind) def test_slice(self): slc = ast.parse("x[::]").body[0].value.slice @@ -780,8 +786,6 @@ class ASTValidatorTests(unittest.TestCase): def test_dict(self): d = ast.Dict([], [ast.Name("x", ast.Load())]) self.expr(d, "same number of keys as values") - d = ast.Dict([None], [ast.Name("x", ast.Load())]) - self.expr(d, "None disallowed") d = ast.Dict([ast.Name("x", ast.Load())], [None]) self.expr(d, "None disallowed") @@ -972,8 +976,8 @@ exec_results = [ ('Module', [('Global', (1, 0), ['v'])]), ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), ('Module', [('Pass', (1, 0))]), -('Module', [('Break', (1, 0))]), -('Module', [('Continue', (1, 0))]), +('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Break', (1, 11))], [])]), +('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Continue', (1, 11))], [])]), ('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)), ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load',)), [('Pass', (1, 14))], [])]), ('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), @@ -986,6 +990,8 @@ exec_results = [ ('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('Expr', (2, 1), ('Await', (2, 1), ('Call', (2, 7), ('Name', (2, 7), 'something', ('Load',)), [], [])))], [], None)]), ('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('AsyncFor', (2, 7), ('Name', (2, 11), 'e', ('Store',)), ('Name', (2, 16), 'i', ('Load',)), [('Expr', (2, 19), ('Num', (2, 19), 1))], [('Expr', (3, 7), ('Num', (3, 7), 2))])], [], None)]), ('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('AsyncWith', (2, 7), [('withitem', ('Name', (2, 12), 'a', ('Load',)), ('Name', (2, 17), 'b', ('Store',)))], [('Expr', (2, 20), ('Num', (2, 20), 1))])], [], None)]), +('Module', [('Expr', (1, 0), ('Dict', (1, 1), [None, ('Num', (1, 10), 2)], [('Dict', (1, 4), [('Num', (1, 4), 1)], [('Num', (1, 6), 2)]), ('Num', (1, 12), 3)]))]), +('Module', [('Expr', (1, 0), ('Set', (1, 1), [('Starred', (1, 1), ('Set', (1, 3), [('Num', (1, 3), 1), ('Num', (1, 6), 2)]), ('Load',)), ('Num', (1, 10), 3)]))]), ] single_results = [ ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), @@ -127,6 +127,8 @@ Release date: 2015-09-06 Core and Builtins ----------------- +- Issue #24975: Fix AST compilation for PEP 448 syntax. + Library ------- diff --git a/Python/ast.c b/Python/ast.c index 8b356fe..c1ce0aa 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -199,8 +199,10 @@ validate_expr(expr_ty exp, expr_context_ty ctx) "Dict doesn't have the same number of keys as values"); return 0; } - return validate_exprs(exp->v.Dict.keys, Load, 0) && - validate_exprs(exp->v.Dict.values, Load, 0); + /* null_ok=1 for keys expressions to allow dict unpacking to work in + dict literals, i.e. ``{**{a:b}}`` */ + return validate_exprs(exp->v.Dict.keys, Load, /*null_ok=*/ 1) && + validate_exprs(exp->v.Dict.values, Load, /*null_ok=*/ 0); case Set_kind: return validate_exprs(exp->v.Set.elts, Load, 0); #define COMP(NAME) \ |