summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXtreak <tir.karthi@gmail.com>2019-02-02 03:10:16 +0530
committerEmily Morehouse <emilyemorehouse@gmail.com>2019-02-01 14:40:16 -0700
commitd4fceaafb8e3f8700d9ec6ab37a51e903392f74f (patch)
treefb3681a954e8d42a3a3161ad38eebcb4eeaf9884
parent85d83ec7c99727476c79feb5c34c65264a99144e (diff)
downloadcpython-git-d4fceaafb8e3f8700d9ec6ab37a51e903392f74f.tar.gz
bpo-35877: Make parenthesis optional for named expression in while statement (GH-11724)
* Add parenthesis optional in named expressions for while statement * Add NEWS entry
-rw-r--r--Grammar/Grammar2
-rw-r--r--Lib/test/test_parser.py1
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2019-02-01-22-38-11.bpo-35877.Jrse8f.rst2
-rw-r--r--Python/graminit.c2
4 files changed, 5 insertions, 2 deletions
diff --git a/Grammar/Grammar b/Grammar/Grammar
index e65a688e4c..a425978059 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -72,7 +72,7 @@ assert_stmt: 'assert' test [',' test]
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
async_stmt: 'async' (funcdef | with_stmt | for_stmt)
if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite]
-while_stmt: 'while' test ':' suite ['else' ':' suite]
+while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite]
for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite]
try_stmt: ('try' ':' suite
((except_clause ':' suite)+
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index 19f1782036..0afeb322e9 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -426,6 +426,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
self.check_suite("(a := 1)")
self.check_suite("(a := a)")
self.check_suite("if (match := pattern.search(data)) is None: pass")
+ self.check_suite("while match := pattern.search(f.read()): pass")
self.check_suite("[y := f(x), y**2, y**3]")
self.check_suite("filtered_data = [y for x in data if (y := f(x)) is None]")
self.check_suite("(y := f(x))")
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-02-01-22-38-11.bpo-35877.Jrse8f.rst b/Misc/NEWS.d/next/Core and Builtins/2019-02-01-22-38-11.bpo-35877.Jrse8f.rst
new file mode 100644
index 0000000000..1fb173fe46
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-02-01-22-38-11.bpo-35877.Jrse8f.rst
@@ -0,0 +1,2 @@
+Make parenthesis optional for named expressions in while statement. Patch by
+Karthikeyan Singaravelan.
diff --git a/Python/graminit.c b/Python/graminit.c
index 6e0f19891b..5cdde2789c 100644
--- a/Python/graminit.c
+++ b/Python/graminit.c
@@ -971,7 +971,7 @@ static arc arcs_42_0[1] = {
{103, 1},
};
static arc arcs_42_1[1] = {
- {26, 2},
+ {99, 2},
};
static arc arcs_42_2[1] = {
{27, 3},