mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
Issue #24619: New approach for tokenizing async/await.
This commit fixes how one-line async-defs and defs are tracked by tokenizer. It allows to correctly parse invalid code such as: >>> async def f(): ... def g(): pass ... async = 10 and valid code such as: >>> async def f(): ... async def g(): pass ... await z As a consequence, is is now possible to have one-line 'async def foo(): await ..' functions: >>> async def foo(): return await bar()
This commit is contained in:
parent
80acc3ebbc
commit
8fb307cd65
13 changed files with 343 additions and 69 deletions
|
|
@ -685,9 +685,7 @@ Execution of Python coroutines can be suspended and resumed at many points
|
|||
(see :term:`coroutine`). In the body of a coroutine, any ``await`` and
|
||||
``async`` identifiers become reserved keywords; :keyword:`await` expressions,
|
||||
:keyword:`async for` and :keyword:`async with` can only be used in
|
||||
coroutine bodies. However, to simplify the parser, these keywords cannot
|
||||
be used on the same line as a function or coroutine (:keyword:`def`
|
||||
statement) header.
|
||||
coroutine bodies.
|
||||
|
||||
Functions defined with ``async def`` syntax are always coroutine functions,
|
||||
even if they do not contain ``await`` or ``async`` keywords.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue