bpo-34616: add flags to allow top-level-await by Carreau · Pull Request #13148 · python/cpython (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

Carreau

1st1

Carreau

@Carreau Carreau marked this pull request as ready for review

May 7, 2019 21:26

@Carreau Carreau changed the titlebpo-34616: [DRAFT] add flags to allow top-level-await bpo-34616: add flags to allow top-level-await

May 8, 2019

tirkarthi

1st1 and others added 8 commits

May 20, 2019 19:08

@1st1 @Carreau

This now works:

import asyncio
import types

print('here')

L = {
    'asyncio': asyncio,
    'a': 'something'
}

code = compile('''
async with asyncio.Lock():
    a = await asyncio.sleep(1, result=42)
''', '', 'single', 0x2000)

f = types.FunctionType(code, L)

print('before', L)
asyncio.run(f())
print('after', L)

@Carreau

In some narrow but rate case; it is useful to be allow to compile code with top-level await features; for example when writing a REPL. This attempt to allow that.

@Carreau

@Carreau

@Carreau

@Carreau

@Carreau @tirkarthi

thanks to tirkarthi

Co-Authored-By: Xtreak tir.karthi@gmail.com

@Carreau

Use itertools product to remove one level of nesting, and make things a tiny bit more readable.

1st1 added a commit to 1st1/cpython that referenced this pull request

May 21, 2019

@1st1

@1st1 1st1 mentioned this pull request

May 21, 2019

ned-deily pushed a commit that referenced this pull request

May 21, 2019

@1st1 @ned-deily