diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2021-05-04 09:00:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-04 09:00:29 (GMT) |
commit | 3b200b2aa648fcc8a2673871807c1463afe00195 (patch) | |
tree | b6859b270dafdfec55374a94e75efa17fb0b49ba | |
parent | 70a071d9e1d65f8c168b4b96a18c86d5230789c5 (diff) | |
download | cpython-3b200b2aa648fcc8a2673871807c1463afe00195.zip cpython-3b200b2aa648fcc8a2673871807c1463afe00195.tar.gz cpython-3b200b2aa648fcc8a2673871807c1463afe00195.tar.bz2 |
bpo-44025: Clarify when '_' is a keyword. (#25873)
In match statements, in case patterns and nowhere else.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
-rw-r--r-- | Doc/reference/compound_stmts.rst | 6 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Documentation/2021-05-03-22-08-08.bpo-44025.gcB7iP.rst | 1 |
2 files changed, 5 insertions, 2 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 96bd9b0..77400a8 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -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 index 0000000..1432236 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2021-05-03-22-08-08.bpo-44025.gcB7iP.rst @@ -0,0 +1 @@ +Clarify when '_' in match statements is a keyword, and when not. |