PEP 505: mention late-stage proposals for similar additions to Javascript (#1237)

This commit is contained in:
Tal Einat 2019-12-02 18:58:11 +02:00 committed by Steve Dower
parent 8910a90d15
commit 9096381fde
1 changed files with 12 additions and 5 deletions

View File

@ -14,8 +14,9 @@ Abstract
Several modern programming languages have so-called "``null``-coalescing" or Several modern programming languages have so-called "``null``-coalescing" or
"``null``- aware" operators, including C# [1]_, Dart [2]_, Perl, Swift, and PHP "``null``- aware" operators, including C# [1]_, Dart [2]_, Perl, Swift, and PHP
(starting in version 7). These operators provide syntactic sugar for common (starting in version 7). There are also stage 3 draft proposals for their
patterns involving null references. addition to ECMAScript (a.k.a. JavaScript) [3]_ [4]_. These operators provide
syntactic sugar for common patterns involving null references.
* The "``null``-coalescing" operator is a binary operator that returns its left * The "``null``-coalescing" operator is a binary operator that returns its left
operand if it is not ``null``. Otherwise it returns its right operand. operand if it is not ``null``. Otherwise it returns its right operand.
@ -91,7 +92,7 @@ operators, the right-hand side is not evaluated until the left-hand side is
determined to be ``None``. determined to be ``None``.
The ``??`` operator binds more tightly than other binary operators as most The ``??`` operator binds more tightly than other binary operators as most
existing implementations of these do not propagate ``None``s (they will existing implementations of these do not propagate ``None`` values (they will
typically raise ``TypeError``). Expressions that are known to potentially typically raise ``TypeError``). Expressions that are known to potentially
result in ``None`` can be substituted for a default value without needing result in ``None`` can be substituted for a default value without needing
additional parentheses. additional parentheses.
@ -235,7 +236,7 @@ conversion to use ``None``-aware operators may look like.
Standard Library Standard Library
---------------- ----------------
Using the ``find-pep505.py`` script[3]_ an analysis of the Python 3.7 standard Using the ``find-pep505.py`` script[5]_ an analysis of the Python 3.7 standard
library discovered up to 678 code snippets that could be replaced with use of library discovered up to 678 code snippets that could be replaced with use of
one of the ``None``-aware operators:: one of the ``None``-aware operators::
@ -848,7 +849,13 @@ References
.. [2] A Tour of the Dart Language: Operators .. [2] A Tour of the Dart Language: Operators
(https://www.dartlang.org/docs/dart-up-and-running/ch02.html#operators) (https://www.dartlang.org/docs/dart-up-and-running/ch02.html#operators)
.. [3] Associated scripts .. [3] Proposal: Nullish Coalescing for JavaScript
(https://github.com/tc39/proposal-nullish-coalescing)
.. [4] Proposal: Optional Chaining for JavaScript
(https://github.com/tc39/proposal-optional-chaining)
.. [5] Associated scripts
(https://github.com/python/peps/tree/master/pep-0505/) (https://github.com/python/peps/tree/master/pep-0505/)
Copyright Copyright