File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed 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
1807
1807
single: assignment expression
1808
1808
single: walrus operator
1809
1809
single: named expression
1810
+ pair: assignment; expression
1810
1811
1811
1812
Assignment expressions
1812
1813
======================
Original file line number Diff line number Diff line change @@ -1861,6 +1861,7 @@ class Helper:
1861
1861
':' : 'SLICINGS DICTIONARYLITERALS' ,
1862
1862
'@' : 'def class' ,
1863
1863
'\\ ' : 'STRINGS' ,
1864
+ ':=' : 'ASSIGNMENTEXPRESSIONS' ,
1864
1865
'_' : 'PRIVATENAMES' ,
1865
1866
'__' : 'PRIVATENAMES SPECIALMETHODS' ,
1866
1867
'`' : 'BACKQUOTES' ,
@@ -1954,6 +1955,7 @@ class Helper:
1954
1955
'ASSERTION' : 'assert' ,
1955
1956
'ASSIGNMENT' : ('assignment' , 'AUGMENTEDASSIGNMENT' ),
1956
1957
'AUGMENTEDASSIGNMENT' : ('augassign' , 'NUMBERMETHODS' ),
1958
+ 'ASSIGNMENTEXPRESSIONS' : ('assignment-expressions' , '' ),
1957
1959
'DELETION' : 'del' ,
1958
1960
'RETURNING' : 'return' ,
1959
1961
'IMPORTING' : 'import' ,
Original file line number Diff line number Diff line change 421
421
'some expressions (like un-parenthesized tuple expressions) '
422
422
'caused a\n'
423
423
'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',
424
452
'async': 'Coroutines\n'
425
453
'**********\n'
426
454
'\n'
You can’t perform that action at this time.
0 commit comments