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: Nested async dict comprehension fails with SyntaxError
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Syntax error with async generator inside dictionary comprehension
View: 33346
Assigned To: Nosy List: hniksic, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-06-29 14:50 by hniksic, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg372582 - (view) Author: Hrvoje Nikšić (hniksic) * Date: 2020-06-29 14:50
Originally brought up on StackOverflow, https://stackoverflow.com/questions/60799366/nested-async-comprehension :

This dict comprehension parses and works correctly:

async def bar():
    return {
        n: await foo(n) for n in [1, 2, 3]
    }

But making it nested fails with a SyntaxError:

async def bar():
    return {
        i: {
            n: await foo(n) for n in [1, 2, 3]
        } for i in [1,2,3]
    }

The error reported is:

  File "<stdin>", line 0
SyntaxError: asynchronous comprehension outside of an asynchronous function
msg372588 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-06-29 14:58
This is a duplicate of issue33346.
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85331
2020-06-29 14:58:26serhiy.storchakasetstatus: open -> closed

superseder: Syntax error with async generator inside dictionary comprehension

nosy: + serhiy.storchaka
messages: + msg372588
resolution: duplicate
stage: resolved
2020-06-29 14:50:41hniksiccreate