mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-125072: Add label for assignment expressions; update tracked section for assignment expression topic (#125074)
This commit is contained in:
parent
a7f0727ca5
commit
447a15190d
3 changed files with 41 additions and 29 deletions
|
@ -417,33 +417,43 @@ topics = {'assert': 'The "assert" statement\n'
|
|||
'caused a\n'
|
||||
'syntax error.\n',
|
||||
'assignment-expressions': 'Assignment expressions\n'
|
||||
'**********************\n'
|
||||
'\n'
|
||||
'An assignment expression (sometimes also called a “named expression”'
|
||||
'\nor “walrus”) assigns an expression to an identifier, while also\n'
|
||||
'returning the value of the expression.\n'
|
||||
'\n'
|
||||
'One common use case is when handling matched regular expressions:\n'
|
||||
'\n'
|
||||
' if matching := pattern.search(data):\n'
|
||||
' do_something(matching)\n'
|
||||
'\n'
|
||||
'Or, when processing a file stream in chunks:\n'
|
||||
'\n'
|
||||
' while chunk := file.read(9000):\n'
|
||||
' process(chunk)\n'
|
||||
'\n'
|
||||
'Assignment expressions must be surrounded by parentheses when used as\n'
|
||||
'expression statements and when used as sub-expressions in slicing,\n'
|
||||
'conditional, lambda, keyword-argument, and comprehension-if\n'
|
||||
'expressions and in assert, with, and assignment statements. In all\n'
|
||||
'other places where they can be used, parentheses are not required,\n'
|
||||
'including in if and while statements.\n'
|
||||
'\n'
|
||||
'Added in version 3.8.\n'
|
||||
'See also:\n'
|
||||
'\n'
|
||||
' **PEP 572** - Assignment Expressions\n',
|
||||
'**********************\n'
|
||||
'\n'
|
||||
' assignment_expression ::= [identifier ":="] '
|
||||
'expression\n'
|
||||
'\n'
|
||||
'An assignment expression (sometimes also called a '
|
||||
'“named expression”\n'
|
||||
'or “walrus”) assigns an "expression" to an '
|
||||
'"identifier", while also\n'
|
||||
'returning the value of the "expression".\n'
|
||||
'\n'
|
||||
'One common use case is when handling matched '
|
||||
'regular expressions:\n'
|
||||
'\n'
|
||||
' if matching := pattern.search(data):\n'
|
||||
' do_something(matching)\n'
|
||||
'\n'
|
||||
'Or, when processing a file stream in chunks:\n'
|
||||
'\n'
|
||||
' while chunk := file.read(9000):\n'
|
||||
' process(chunk)\n'
|
||||
'\n'
|
||||
'Assignment expressions must be surrounded by '
|
||||
'parentheses when used as\n'
|
||||
'expression statements and when used as '
|
||||
'sub-expressions in slicing,\n'
|
||||
'conditional, lambda, keyword-argument, and '
|
||||
'comprehension-if\n'
|
||||
'expressions and in "assert", "with", and '
|
||||
'"assignment" statements. In\n'
|
||||
'all other places where they can be used, '
|
||||
'parentheses are not required,\n'
|
||||
'including in "if" and "while" statements.\n'
|
||||
'\n'
|
||||
'Added in version 3.8: See **PEP 572** for more '
|
||||
'details about\n'
|
||||
'assignment expressions.\n',
|
||||
'async': 'Coroutines\n'
|
||||
'**********\n'
|
||||
'\n'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue