PEP 640: Update post history and fix a bit of markup. (#1664)
Update post history and fix a bit of markup, and address reviewer comments.
This commit is contained in:
parent
4e5d851eb7
commit
ee89115a63
25
pep-0640.rst
25
pep-0640.rst
|
@ -6,7 +6,7 @@ Type: Standards Track
|
|||
Content-Type: text/x-rst
|
||||
Created: 04-Oct-2020
|
||||
Python-Version: 3.10
|
||||
Post-History:
|
||||
Post-History: 19-Oct-2020
|
||||
|
||||
Abstract
|
||||
========
|
||||
|
@ -44,11 +44,11 @@ assigned to anything. The choice of ``"_"`` there matches the use of ``"_"``
|
|||
in other languages, but the semantic difference with ``"_"`` elsewhere in
|
||||
Python is significant.
|
||||
|
||||
This PEP proposes to allow a special token, ``?``, to be used instead. This
|
||||
has most of the benefits of ``"_"`` without affecting other uses of that
|
||||
otherwise regular variable. Allowing the use of the same wildcard pattern
|
||||
would make pattern matching and unpacking assignment more consistent with
|
||||
each other.
|
||||
This PEP proposes to allow a special token, ``"?"``, to be used instead of
|
||||
any valid name in assignment. This has most of the benefits of ``"_"``
|
||||
without affecting other uses of that otherwise regular variable. Allowing
|
||||
the use of the same wildcard pattern would make pattern matching and
|
||||
unpacking assignment more consistent with each other.
|
||||
|
||||
Rationale
|
||||
=========
|
||||
|
@ -74,7 +74,7 @@ special-casing of ``"_"`` for this wildcard pattern purpose is still
|
|||
problematic: the different semantics *and meaning* of ``"_"`` inside pattern
|
||||
matching and outside of it means a break in consistency in Python.
|
||||
|
||||
Introducing ``?`` as special syntax for unused variables *both inside and
|
||||
Introducing ``"?"`` as special syntax for unused variables *both inside and
|
||||
outside pattern matching* allows us to retain that consistency. It avoids
|
||||
the conflict with internationalization *or any other uses of _ as a
|
||||
variable*. It makes unpacking assignment align more closely with pattern
|
||||
|
@ -124,7 +124,9 @@ nothing else it seems more sensible to allow the use of the single ``"?"``
|
|||
in other cases.
|
||||
|
||||
Using ``"?"`` in augmented assignment (``? *= 2``) is not allowed, since
|
||||
``"?"`` can only be used for assignment.
|
||||
``"?"`` can only be used for assignment. Having multiple occurrences of
|
||||
``"?"`` is valid, just like when assigning to names, and the assignments do
|
||||
not interfere with each other.
|
||||
|
||||
Backwards Compatibility
|
||||
=======================
|
||||
|
@ -132,7 +134,8 @@ Backwards Compatibility
|
|||
Introducing a new token means there are no backward compatibility concerns.
|
||||
No valid syntax changes meaning.
|
||||
|
||||
"?" is not considered an identifier, so str.isidentifier() does not change.
|
||||
``"?"`` is not considered an identifier, so ``str.isidentifier()`` does not
|
||||
change.
|
||||
|
||||
The AST does change in an incompatible way, as the identifier of a Name
|
||||
token can now be empty. Code using the AST will have to be adjusted
|
||||
|
@ -141,14 +144,14 @@ accordingly.
|
|||
How to Teach This
|
||||
=================
|
||||
|
||||
``?`` can be introduced along with unpacking assignment, explaining it is
|
||||
``"?"`` can be introduced along with unpacking assignment, explaining it is
|
||||
special syntax for 'unused' and mentioning that it can also be used in other
|
||||
places. Alternatively, it could be introduced as part of an explanation on
|
||||
assignment in ``for`` loops, showing an example where the loop variable is
|
||||
unused.
|
||||
|
||||
PEP 636 discusses how to teach ``"_"``, and can simply replace ``"_"`` with
|
||||
``?``, perhaps noting that ``?`` is similarly usable in other contexts.
|
||||
``"?"``, perhaps noting that ``"?"`` is similarly usable in other contexts.
|
||||
|
||||
Reference Implementation
|
||||
========================
|
||||
|
|
Loading…
Reference in New Issue