pep-0492: Add operator precedence table for await expression.
This commit is contained in:
parent
a09fa75d7d
commit
32b06ca706
74
pep-0492.txt
74
pep-0492.txt
|
@ -164,13 +164,80 @@ It is a ``TypeError`` to pass anything other than an *awaitable* object
|
|||
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 @@ Expression Should be written as
|
|||
``await -coro()`` ``await (-coro())``
|
||||
================================== ==================================
|
||||
|
||||
|
||||
See `Grammar Updates`_ section for details.
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue