[Python-checkins] peps: pep-0492: Add operator precedence table for await expression.
yury.selivanov
python-checkins at python.org
Thu Apr 30 00:07:25 CEST 2015
https://hg.python.org/peps/rev/d355918bc0d7
changeset: 5807:d355918bc0d7
user: Yury Selivanov <yselivanov at sprymix.com>
date: Wed Apr 29 18:07:18 2015 -0400
summary:
pep-0492: Add operator precedence table for await expression.
files:
pep-0492.txt | 74 +++++++++++++++++++++++++++++++++++++--
1 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/pep-0492.txt b/pep-0492.txt
--- a/pep-0492.txt
+++ b/pep-0492.txt
@@ -164,13 +164,80 @@
to an ``await`` expression.
-Syntax of "await" expression
-''''''''''''''''''''''''''''
+Updated operator precedence table
+'''''''''''''''''''''''''''''''''
``await`` keyword is defined differently from ``yield`` and ``yield
-from``. The main difference is that *await expressions* do not require
+from`` in the Grammar.
+
+The key difference is that *await expressions* do not require
parentheses around them most of the times.
+Also, ``yield from`` allows any expression as its argument, including
+expressions like ``yield from a() + b()``, that would be parsed as
+``yield from (a() + b())``, which is almost always a bug. In general,
+the result of any arithmetic operation is not an *awaitable* object.
+To avoid this kind of mistakes, it was decided to make ``await``
+precedence lower than ``[]``, ``()``, and ``.``, but higher than ``**``
+operators.
+
++------------------------------+-----------------------------------+
+| Operator | Description |
++==============================+===================================+
+| ``yield``, ``yield from`` | Yield expression |
++------------------------------+-----------------------------------+
+| ``lambda`` | Lambda expression |
++------------------------------+-----------------------------------+
+| ``if`` -- ``else`` | Conditional expression |
++------------------------------+-----------------------------------+
+| ``or`` | Boolean OR |
++------------------------------+-----------------------------------+
+| ``and`` | Boolean AND |
++------------------------------+-----------------------------------+
+| ``not`` ``x`` | Boolean NOT |
++------------------------------+-----------------------------------+
+| ``in``, ``not in``, | Comparisons, including membership |
+| ``is``, ``is not``, ``<``, | tests and identity tests |
+| ``<=``, ``>``, ``>=``, | |
+| ``!=``, ``==`` | |
++------------------------------+-----------------------------------+
+| ``|`` | Bitwise OR |
++------------------------------+-----------------------------------+
+| ``^`` | Bitwise XOR |
++------------------------------+-----------------------------------+
+| ``&`` | Bitwise AND |
++------------------------------+-----------------------------------+
+| ``<<``, ``>>`` | Shifts |
++------------------------------+-----------------------------------+
+| ``+``, ``-`` | Addition and subtraction |
++------------------------------+-----------------------------------+
+| ``*``, ``@``, ``/``, ``//``, | Multiplication, matrix |
+| ``%`` | multiplication, division, |
+| | remainder |
++------------------------------+-----------------------------------+
+| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |
++------------------------------+-----------------------------------+
+| ``**`` | Exponentiation |
++------------------------------+-----------------------------------+
+| ``await`` | Await expression |
++------------------------------+-----------------------------------+
+| ``x[index]``, | Subscription, slicing, |
+| ``x[index:index]``, | call, attribute reference |
+| ``x(arguments...)``, | |
+| ``x.attribute`` | |
++------------------------------+-----------------------------------+
+| ``(expressions...)``, | Binding or tuple display, |
+| ``[expressions...]``, | list display, |
+| ``{key: value...}``, | dictionary display, |
+| ``{expressions...}`` | set display |
++------------------------------+-----------------------------------+
+
+See `Grammar Updates`_ section for details.
+
+
+Examples of "await" expressions
+'''''''''''''''''''''''''''''''
+
Valid syntax examples:
================================== ==================================
@@ -197,7 +264,6 @@
``await -coro()`` ``await (-coro())``
================================== ==================================
-
See `Grammar Updates`_ section for details.
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list