lib2to3: Support named assignment expressions (GH-12702) · python/cpython@1098671

@@ -67,8 +67,8 @@ assert_stmt: 'assert' test [',' test]

67676868

compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt

6969

async_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]

7272

for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]

7373

try_stmt: ('try' ':' suite

7474

((except_clause ':' suite)+

@@ -91,6 +91,7 @@ testlist_safe: old_test [(',' old_test)+ [',']]

9191

old_test: or_test | old_lambdef

9292

old_lambdef: 'lambda' [varargslist] ':' old_test

939394+

namedexpr_test: test [':=' test]

9495

test: or_test ['if' or_test 'else' test] | lambdef

9596

or_test: and_test ('or' and_test)*

9697

and_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))* [','] )

116117

lambdef: 'lambda' [varargslist] ':' test

117118

trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME

118119

subscriptlist: 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.

139140

argument: ( test [comp_for] |

141+

test ':=' test |

140142

test '=' test |

141143

'**' test |

142144

'*' test )