]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-125072: Add label for assignment expressions; update tracked section for assignmen...
authorEmily Morehouse <emily@python.org>
Mon, 7 Oct 2024 22:51:14 +0000 (16:51 -0600)
committerGitHub <noreply@github.com>
Mon, 7 Oct 2024 22:51:14 +0000 (22:51 +0000)
Doc/reference/expressions.rst
Doc/tools/extensions/pyspecific.py
Lib/pydoc_data/topics.py

index ab72ad49d041e14e1e7bb51f4b351b14f48e05cf..decde0d297cf59b11d4a89d0e0404f89321ca8cb 100644 (file)
@@ -1809,6 +1809,8 @@ returns a boolean value regardless of the type of its argument
    single: named expression
    pair: assignment; expression
 
+.. _assignment-expressions:
+
 Assignment expressions
 ======================
 
index c89b1693343b4e3c6c4c087a8ea4144b3205144e..b6623a2b8e01f16e75a08d32c7342641b9ddcb99 100644 (file)
@@ -353,8 +353,8 @@ class MiscNews(SphinxDirective):
 # Support for building "topic help" for pydoc
 
 pydoc_topic_labels = [
-    'assert', 'assignment', 'async', 'atom-identifiers', 'atom-literals',
-    'attribute-access', 'attribute-references', 'augassign', 'await',
+    'assert', 'assignment', 'assignment-expressions', 'async',  'atom-identifiers',
+    'atom-literals', 'attribute-access', 'attribute-references', 'augassign', 'await',
     'binary', 'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object',
     'bltin-null-object', 'bltin-type-objects', 'booleans',
     'break', 'callable-types', 'calls', 'class', 'comparisons', 'compound',
index 97bb4eb52f43864b0900e7d3c6e461c2480d233e..ae56c1366084723911594695469f3b0a6260f7e8 100644 (file)
@@ -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'