diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-07-06 21:44:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-06 21:44:16 (GMT) |
commit | 41db8ffc59566b8552f9cce4452ee8afad00aa63 (patch) | |
tree | b6f575f4b24c370e5bdf816c8f25170db2668a4b /Lib/test/test_builtin.py | |
parent | aa7f7756149a10c64d01f583b71e91814db886ab (diff) | |
download | cpython-41db8ffc59566b8552f9cce4452ee8afad00aa63.zip cpython-41db8ffc59566b8552f9cce4452ee8afad00aa63.tar.gz cpython-41db8ffc59566b8552f9cce4452ee8afad00aa63.tar.bz2 |
bpo-41218: Only mark async code with CO_COROUTINE. (GH-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.
(cherry picked from commit bd46174a5a09a54e5ae1077909f923f56a7cf710)
Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com>
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r-- | Lib/test/test_builtin.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 48b0e33..f47689d 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -370,6 +370,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. |