]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44025: Clarify when '_' is a keyword. (#25873)
authorTerry Jan Reedy <tjreedy@udel.edu>
Tue, 4 May 2021 09:00:29 +0000 (05:00 -0400)
committerGitHub <noreply@github.com>
Tue, 4 May 2021 09:00:29 +0000 (11:00 +0200)
In match statements, in case patterns and nowhere else.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Doc/reference/compound_stmts.rst
Misc/NEWS.d/next/Documentation/2021-05-03-22-08-08.bpo-44025.gcB7iP.rst [new file with mode: 0644]

index 96bd9b028d504484a61dac0fe9d981c76aa751a2..77400a8d8504f3e3e8ee871d32a8bcd1b955a587 100644 (file)
@@ -797,7 +797,7 @@ Syntax:
    capture_pattern: !'_' NAME
 
 A single underscore ``_`` is not a capture pattern (this is what ``!'_'``
-expresses). And is instead treated as a :token:`wildcard_pattern`.
+expresses). It is instead treated as a :token:`wildcard_pattern`.
 
 In a given pattern, a given name can only be bound once.  E.g.
 ``case x, x: ...`` is invalid while ``case [x] | x: ...`` is allowed.
@@ -820,7 +820,9 @@ and binds no name.  Syntax:
 .. productionlist:: python-grammar
    wildcard_pattern: '_'
 
-``_`` is a :ref:`soft keyword <soft-keywords>`.
+``_`` is a :ref:`soft keyword <soft-keywords>` within any pattern,
+but only within patterns.  It is an identifier, as usual, even within
+``match`` headers, ``guards``, and ``case`` blocks.
 
 In simple terms, ``_`` will always succeed.
 
diff --git a/Misc/NEWS.d/next/Documentation/2021-05-03-22-08-08.bpo-44025.gcB7iP.rst b/Misc/NEWS.d/next/Documentation/2021-05-03-22-08-08.bpo-44025.gcB7iP.rst
new file mode 100644 (file)
index 0000000..1432236
--- /dev/null
@@ -0,0 +1 @@
+Clarify when '_' in match statements is a keyword, and when not.