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 marked this pull request as ready for review
Carreau changed the title
bpo-34616: [DRAFT] add flags to allow top-level-await bpo-34616: add flags to allow top-level-await
1st1 and others added 8 commits
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)
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.
thanks to tirkarthi
Co-Authored-By: Xtreak tir.karthi@gmail.com
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
1st1 mentioned this pull request
ned-deily pushed a commit that referenced this pull request