GeezerVison is showing github.com — gh-94947: Disallow parsing walrus with feature_version < (3, 8) (GH-9… · python/cpython@7dc236d
File treeExpand file treeCollapse file tree Open diff view settings Misc/NEWS.d/next/Core and Builtins
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Grammar/python.gram +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -660,7 +660,9 @@ star_named_expression[expr_ty]: | 660 | 660 | | named_expression | 661 | 661 |
| 662 | 662 | assignment_expression[expr_ty]: | 663 | | - | a=NAME ':=' ~ b=expression { _PyAST_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } | | 663 | + | a=NAME ':=' ~ b=expression { | | 664 | + CHECK_VERSION(expr_ty, 8, "Assignment expressions are", | | 665 | + _PyAST_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA)) } | 664 | 666 |
| 665 | 667 | named_expression[expr_ty]: | 666 | 668 | | assignment_expression | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_ast.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -743,6 +743,11 @@ def test_issue40614_feature_version(self): | 743 | 743 | with self.assertRaises(SyntaxError): | 744 | 744 | ast.parse('f"{x=}"', feature_version=(3, 7)) | 745 | 745 |
| | 746 | + def test_assignment_expression_feature_version(self): | | 747 | + ast.parse('(x := 0)', feature_version=(3, 8)) | | 748 | + with self.assertRaises(SyntaxError): | | 749 | + ast.parse('(x := 0)', feature_version=(3, 7)) | | 750 | + | 746 | 751 | def test_constant_as_name(self): | 747 | 752 | for constant in "True", "False", "None": | 748 | 753 | expr = ast.Expression(ast.Name(constant, ast.Load())) | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +:func:`ast.parse` will no longer parse assignment expressions when passed ``feature_version`` less than ``(3, 8)``. Patch by Shantanu Jain. |
Collapse file Copy file name to clipboardExpand all lines: Parser/parser.c +1-1Lines changed: 1 addition & 1 deletion
|