This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misleading exeption for await in comprehensions.
Type: behavior Stage: resolved
Components: asyncio, Interpreter Core Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: gvanrossum, levkivskyi, ncoghlan, python-dev, vstinner, yselivanov
Priority: normal Keywords: needs review, patch

Created on 2015-06-29 11:28 by levkivskyi, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
awaitcomp.patch yselivanov, 2015-06-29 16:29 review
Messages (4)
msg245931 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2015-06-29 11:28
The following code:

async def foo():
    lst = [await coro(i) for i in range(10)]
    return lst

gives

SyntaxError: 'await' outside async function

I understand that this is because the comprehensions are implemented using a function scope (see also #10544), but such behavior is unintuitive.

IMO there are two possibilities here:
1) make comprehensions behave more like a for loop;
2) change the exception text to something like "SyntaxError: 'await's in comprehensions are not supported".

I understand that the first option is probably not for 3.5 (it is beta already), but I will be happy if the second option will be implemented in 3.5
msg245951 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-29 16:29
Thanks for discovering this, Ivan.  The patch is attached.
msg245995 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-30 16:49
New changeset 30b676e8b21f by Yury Selivanov in branch '3.5':
Issue #24528: Improve error message for awaits in comprehensions
https://hg.python.org/cpython/rev/30b676e8b21f

New changeset 9598bc916186 by Yury Selivanov in branch 'default':
Merge 3.5 (Issue #24528)
https://hg.python.org/cpython/rev/9598bc916186
msg246030 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2015-07-01 08:34
Yury, thank you for the patch, the error message is much clearer now.
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68716
2015-07-01 08:34:38levkivskyisetmessages: + msg246030
2015-06-30 16:49:56yselivanovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-06-30 16:49:26python-devsetnosy: + python-dev
messages: + msg245995
2015-06-29 16:29:18yselivanovsetfiles: + awaitcomp.patch

nosy: + ncoghlan
messages: + msg245951

keywords: + needs review, patch
stage: patch review
2015-06-29 13:46:27yselivanovsetassignee: yselivanov
2015-06-29 11:28:43levkivskyicreate