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 2020-06-29 14:58 by serhiy.storchaka. 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
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