Skip to content

Commit ae4f857

Browse files
bpo-44025: Clarify when '_' is a keyword. (GH-25873)
In match statements, in case patterns and nowhere else. Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 3b200b2) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent aa0ce16 commit ae4f857

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ Syntax:
797797
capture_pattern: !'_' NAME
798798

799799
A single underscore ``_`` is not a capture pattern (this is what ``!'_'``
800-
expresses). And is instead treated as a :token:`wildcard_pattern`.
800+
expresses). It is instead treated as a :token:`wildcard_pattern`.
801801

802802
In a given pattern, a given name can only be bound once. E.g.
803803
``case x, x: ...`` is invalid while ``case [x] | x: ...`` is allowed.
@@ -820,7 +820,9 @@ and binds no name. Syntax:
820820
.. productionlist:: python-grammar
821821
wildcard_pattern: '_'
822822

823-
``_`` is a :ref:`soft keyword <soft-keywords>`.
823+
``_`` is a :ref:`soft keyword <soft-keywords>` within any pattern,
824+
but only within patterns. It is an identifier, as usual, even within
825+
``match`` headers, ``guards``, and ``case`` blocks.
824826

825827
In simple terms, ``_`` will always succeed.
826828

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify when '_' in match statements is a keyword, and when not.

0 commit comments

Comments
 (0)