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
|
Content-Type: text/x-rst
|
||||||
Created: 04-Oct-2020
|
Created: 04-Oct-2020
|
||||||
Python-Version: 3.10
|
Python-Version: 3.10
|
||||||
Post-History:
|
Post-History: 19-Oct-2020
|
||||||
|
|
||||||
Abstract
|
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
|
in other languages, but the semantic difference with ``"_"`` elsewhere in
|
||||||
Python is significant.
|
Python is significant.
|
||||||
|
|
||||||
This PEP proposes to allow a special token, ``?``, to be used instead. This
|
This PEP proposes to allow a special token, ``"?"``, to be used instead of
|
||||||
has most of the benefits of ``"_"`` without affecting other uses of that
|
any valid name in assignment. This has most of the benefits of ``"_"``
|
||||||
otherwise regular variable. Allowing the use of the same wildcard pattern
|
without affecting other uses of that otherwise regular variable. Allowing
|
||||||
would make pattern matching and unpacking assignment more consistent with
|
the use of the same wildcard pattern would make pattern matching and
|
||||||
each other.
|
unpacking assignment more consistent with each other.
|
||||||
|
|
||||||
Rationale
|
Rationale
|
||||||
=========
|
=========
|
||||||
|
@ -74,7 +74,7 @@ special-casing of ``"_"`` for this wildcard pattern purpose is still
|
||||||
problematic: the different semantics *and meaning* of ``"_"`` inside pattern
|
problematic: the different semantics *and meaning* of ``"_"`` inside pattern
|
||||||
matching and outside of it means a break in consistency in Python.
|
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
|
outside pattern matching* allows us to retain that consistency. It avoids
|
||||||
the conflict with internationalization *or any other uses of _ as a
|
the conflict with internationalization *or any other uses of _ as a
|
||||||
variable*. It makes unpacking assignment align more closely with pattern
|
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.
|
in other cases.
|
||||||
|
|
||||||
Using ``"?"`` in augmented assignment (``? *= 2``) is not allowed, since
|
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
|
Backwards Compatibility
|
||||||
=======================
|
=======================
|
||||||
|
@ -132,7 +134,8 @@ Backwards Compatibility
|
||||||
Introducing a new token means there are no backward compatibility concerns.
|
Introducing a new token means there are no backward compatibility concerns.
|
||||||
No valid syntax changes meaning.
|
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
|
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
|
token can now be empty. Code using the AST will have to be adjusted
|
||||||
|
@ -141,14 +144,14 @@ accordingly.
|
||||||
How to Teach This
|
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
|
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
|
places. Alternatively, it could be introduced as part of an explanation on
|
||||||
assignment in ``for`` loops, showing an example where the loop variable is
|
assignment in ``for`` loops, showing an example where the loop variable is
|
||||||
unused.
|
unused.
|
||||||
|
|
||||||
PEP 636 discusses how to teach ``"_"``, and can simply replace ``"_"`` with
|
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
|
Reference Implementation
|
||||||
========================
|
========================
|
||||||
|
|
Loading…
Reference in New Issue