From 410ba6dd4841dc445ce8e0cd3e63ade2fa92ddc4 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 24 Jun 2020 07:46:54 -0700 Subject: [PATCH] PEP 622: drop restriction on ._ an _.a --- pep-0622.rst | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pep-0622.rst b/pep-0622.rst index 20bccfd74..c693b62c8 100644 --- a/pep-0622.rst +++ b/pep-0622.rst @@ -317,15 +317,6 @@ adding it is not prohibited, so ``.Color.BLACK`` is the same as ``Color.BLACK``. See `rejected ideas`_ for other syntactic alternatives that were considered for constant value pattern. -The initial name must not be ``_`` because ``_`` has a special meaning in -pattern matching, so these are invalid:: - - case ._: ... - case _.a: ... - -However, ``a._`` is legal and loads the attribute with name ``_`` of the -object ``a`` as usual. - .. _sequence_pattern: @@ -1404,6 +1395,24 @@ provide the *values* for all positional arguments at once. And there seems to be no practical need for it, so it was scrapped. (It could easily be added at a later stage if a need arises.) +Disallow ``._`` and ``_.a`` in constant value patterns +------------------------------------------------------ + +The first public draft said that the initial name in a constant value +pattern must not be ``_`` because ``_`` has a special meaning in +pattern matching, so these would be invalid:: + + case ._: ... + case _.a: ... + +(However, ``a._`` would be legal and load the attribute with name +``_`` of the object ``a`` as usual.) + +There was some pushback against this on python-dev (some people have a +legitimate use for ``_`` as an important global variable, esp. in +i18n) and the only reason for this prohibition was to prevent some +user confusion. But it's not the hill to die on. + .. _deferred ideas: