Skip to content

[3.13] gh-81263: Add assignment expressions to help (GH-124641) #124713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,7 @@ returns a boolean value regardless of the type of its argument
single: assignment expression
single: walrus operator
single: named expression
pair: assignment; expression

Assignment expressions
======================
Expand Down
2 changes: 2 additions & 0 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,7 @@ class Helper:
':': 'SLICINGS DICTIONARYLITERALS',
'@': 'def class',
'\\': 'STRINGS',
':=': 'ASSIGNMENTEXPRESSIONS',
'_': 'PRIVATENAMES',
'__': 'PRIVATENAMES SPECIALMETHODS',
'`': 'BACKQUOTES',
Expand Down Expand Up @@ -1954,6 +1955,7 @@ class Helper:
'ASSERTION': 'assert',
'ASSIGNMENT': ('assignment', 'AUGMENTEDASSIGNMENT'),
'AUGMENTEDASSIGNMENT': ('augassign', 'NUMBERMETHODS'),
'ASSIGNMENTEXPRESSIONS': ('assignment-expressions', ''),
'DELETION': 'del',
'RETURNING': 'return',
'IMPORTING': 'import',
Expand Down
28 changes: 28 additions & 0 deletions Lib/pydoc_data/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,34 @@
'some expressions (like un-parenthesized tuple expressions) '
'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',
'async': 'Coroutines\n'
'**********\n'
'\n'
Expand Down
Loading