File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1807,6 +1807,7 @@ returns a boolean value regardless of the type of its argument
18071807 single: assignment expression
18081808 single: walrus operator
18091809 single: named expression
1810+ pair: assignment; expression
18101811
18111812Assignment expressions
18121813======================
Original file line number Diff line number Diff line change @@ -1861,6 +1861,7 @@ class Helper:
18611861 ':' : 'SLICINGS DICTIONARYLITERALS' ,
18621862 '@' : 'def class' ,
18631863 '\\ ' : 'STRINGS' ,
1864+ ':=' : 'ASSIGNMENTEXPRESSIONS' ,
18641865 '_' : 'PRIVATENAMES' ,
18651866 '__' : 'PRIVATENAMES SPECIALMETHODS' ,
18661867 '`' : 'BACKQUOTES' ,
@@ -1954,6 +1955,7 @@ class Helper:
19541955 'ASSERTION' : 'assert' ,
19551956 'ASSIGNMENT' : ('assignment' , 'AUGMENTEDASSIGNMENT' ),
19561957 'AUGMENTEDASSIGNMENT' : ('augassign' , 'NUMBERMETHODS' ),
1958+ 'ASSIGNMENTEXPRESSIONS' : ('assignment-expressions' , '' ),
19571959 'DELETION' : 'del' ,
19581960 'RETURNING' : 'return' ,
19591961 'IMPORTING' : 'import' ,
Original file line number Diff line number Diff line change 421421 'some expressions (like un-parenthesized tuple expressions) '
422422 'caused a\n'
423423 'syntax error.\n',
424+ 'assignment-expressions': 'Assignment expressions\n'
425+ '**********************\n'
426+ '\n'
427+ 'An assignment expression (sometimes also called a “named expression”'
428+ '\nor “walrus”) assigns an expression to an identifier, while also\n'
429+ 'returning the value of the expression.\n'
430+ '\n'
431+ 'One common use case is when handling matched regular expressions:\n'
432+ '\n'
433+ ' if matching := pattern.search(data):\n'
434+ ' do_something(matching)\n'
435+ '\n'
436+ 'Or, when processing a file stream in chunks:\n'
437+ '\n'
438+ ' while chunk := file.read(9000):\n'
439+ ' process(chunk)\n'
440+ '\n'
441+ 'Assignment expressions must be surrounded by parentheses when used as\n'
442+ 'expression statements and when used as sub-expressions in slicing,\n'
443+ 'conditional, lambda, keyword-argument, and comprehension-if\n'
444+ 'expressions and in assert, with, and assignment statements. In all\n'
445+ 'other places where they can be used, parentheses are not required,\n'
446+ 'including in if and while statements.\n'
447+ '\n'
448+ 'Added in version 3.8.\n'
449+ 'See also:\n'
450+ '\n'
451+ ' **PEP 572** - Assignment Expressions\n',
424452 'async': 'Coroutines\n'
425453 '**********\n'
426454 '\n'
You can’t perform that action at this time.
0 commit comments