lib2to3: Support named assignment expressions (GH-12702) · python/cpython@1098671
@@ -67,8 +67,8 @@ assert_stmt: 'assert' test [',' test]
67676868compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
6969async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
70-if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
71-while_stmt: 'while' test ':' suite ['else' ':' suite]
70+if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite]
71+while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite]
7272for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
7373try_stmt: ('try' ':' suite
7474 ((except_clause ':' suite)+
@@ -91,6 +91,7 @@ testlist_safe: old_test [(',' old_test)+ [',']]
9191old_test: or_test | old_lambdef
9292old_lambdef: 'lambda' [varargslist] ':' old_test
939394+namedexpr_test: test [':=' test]
9495test: or_test ['if' or_test 'else' test] | lambdef
9596or_test: and_test ('or' and_test)*
9697and_test: not_test ('and' not_test)*
@@ -111,8 +112,8 @@ atom: ('(' [yield_expr|testlist_gexp] ')' |
111112'{' [dictsetmaker] '}' |
112113'`' testlist1 '`' |
113114 NAME | NUMBER | STRING+ | '.' '.' '.')
114-listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
115-testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
115+listmaker: (namedexpr_test|star_expr) ( comp_for | (',' (namedexpr_test|star_expr))* [','] )
116+testlist_gexp: (namedexpr_test|star_expr) ( comp_for | (',' (namedexpr_test|star_expr))* [','] )
116117lambdef: 'lambda' [varargslist] ':' test
117118trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
118119subscriptlist: subscript (',' subscript)* [',']
@@ -137,6 +138,7 @@ arglist: argument (',' argument)* [',']
137138# multiple (test comp_for) arguments are blocked; keyword unpackings
138139# that precede iterable unpackings are blocked; etc.
139140argument: ( test [comp_for] |
141+ test ':=' test |
140142 test '=' test |
141143'**' test |
142144'*' test )