From: Serhiy Storchaka Date: Thu, 13 Feb 2020 23:53:59 +0000 (+0200) Subject: bpo-39545: Document restrictions on "await" and "async for" in f-strings. (GH-18459) X-Git-Tag: v3.6.11rc1~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cebe9ee988837b292f2c571e194ed11e7cd4abbb;p=thirdparty%2FPython%2Fcpython.git bpo-39545: Document restrictions on "await" and "async for" in f-strings. (GH-18459) --- diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index b4e95b90dbc7..8d050a69a931 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -730,7 +730,7 @@ Functions defined with ``async def`` syntax are always coroutine functions, even if they do not contain ``await`` or ``async`` keywords. It is a :exc:`SyntaxError` to use ``yield from`` expressions in -``async def`` coroutines. Using ``await`` in :keyword:`f-strings` will also produce a :exc:`SyntaxError`. +``async def`` coroutines. An example of a coroutine function:: diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index bee02443e621..3a03b9471623 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -683,6 +683,15 @@ can contain line breaks (e.g. in triple-quoted strings), but they cannot contain comments. Each expression is evaluated in the context where the formatted string literal appears, in order from left to right. +.. index:: + keyword: await + single: async for; in comprehensions + +An :keyword:`await` expression and comprehensions containing an +:keyword:`async for` clause are illegal in the expression in formatted +string literals. (The reason is a problem with the implementation --- +this restriction is lifted in Python 3.7). + If a conversion is specified, the result of evaluating the expression is converted before formatting. Conversion ``'!s'`` calls :func:`str` on the result, ``'!r'`` calls :func:`repr`, and ``'!a'`` calls :func:`ascii`.