Skip to content
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
6 changes: 4 additions & 2 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Comment thread
terryjreedy marked this conversation as resolved.

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify when '_' in match statements is a keyword, and when not.