mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
bpo-41218: Only mark async code with CO_COROUTINE. (#21357)
3.8.3 had a regression where compiling with ast.PyCF_ALLOW_TOP_LEVEL_AWAIT woudl agressively mark things are coroutine even if there were not.
This commit is contained in:
parent
a103e73ce8
commit
bd46174a5a
3 changed files with 29 additions and 4 deletions
|
@ -371,6 +371,25 @@ class BuiltinTest(unittest.TestCase):
|
|||
rv = ns['f']()
|
||||
self.assertEqual(rv, tuple(expected))
|
||||
|
||||
def test_compile_top_level_await_no_coro(self):
|
||||
"""Make sure top level non-await codes get the correct coroutine flags.
|
||||
"""
|
||||
modes = ('single', 'exec')
|
||||
code_samples = [
|
||||
'''def f():pass\n''',
|
||||
'''[x for x in l]'''
|
||||
]
|
||||
for mode, code_sample in product(modes, code_samples):
|
||||
source = dedent(code_sample)
|
||||
co = compile(source,
|
||||
'?',
|
||||
mode,
|
||||
flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
|
||||
|
||||
self.assertNotEqual(co.co_flags & CO_COROUTINE, CO_COROUTINE,
|
||||
msg=f"source={source} mode={mode}")
|
||||
|
||||
|
||||
def test_compile_top_level_await(self):
|
||||
"""Test whether code some top level await can be compiled.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue