bpo-44025: Clarify when '_' is a keyword. (GH-25873)

In match statements, in case patterns and nowhere else.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 3b200b2aa6)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2021-05-04 04:36:50 -07:00 committed by GitHub
parent aa0ce1615f
commit ae4f857499
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View 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.

View file

@ -0,0 +1 @@
Clarify when '_' in match statements is a keyword, and when not.