Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Grammar/Grammar
Original file line number Diff line number Diff line change
Expand Up @@ -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)+
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def test_named_expressions(self):
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))")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make parenthesis optional for named expressions in while statement. Patch by
Karthikeyan Singaravelan.
2 changes: 1 addition & 1 deletion Python/graminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down