diff options
author | scoder <stefan_ml@behnel.de> | 2022-07-29 19:56:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-29 19:56:50 +0200 |
commit | 11e4b1f11c3849622007481d92c3589ce5cfbec8 (patch) | |
tree | 232e3e72601ada7959a3e03ba6068795b58856af | |
parent | 820b444ddcbfae7e393298d3a6478e742aa12022 (diff) | |
download | cython-11e4b1f11c3849622007481d92c3589ce5cfbec8.tar.gz |
Make Cython async functions set CO_COROUTINE and CO_ASYNC_GENERATOR code flags (GH-4902)
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 6 | ||||
-rw-r--r-- | Cython/Utility/ModuleSetupCode.c | 7 | ||||
-rw-r--r-- | tests/run/test_coroutines_pep492.pyx | 8 |
3 files changed, 18 insertions, 3 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index ab228c552..130c4f1c7 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -9839,6 +9839,12 @@ class CodeObjectNode(ExprNode): flags.append('CO_VARARGS') if self.def_node.starstar_arg: flags.append('CO_VARKEYWORDS') + if self.def_node.is_asyncgen: + flags.append('CO_ASYNC_GENERATOR') + elif self.def_node.is_coroutine: + flags.append('CO_COROUTINE') + elif self.def_node.is_generator: + flags.append('CO_GENERATOR') code.putln("%s = (PyObject*)__Pyx_PyCode_New(%d, %d, %d, %d, 0, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s); %s" % ( self.result_code, diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c index cc3f658b0..d54426a4f 100644 --- a/Cython/Utility/ModuleSetupCode.c +++ b/Cython/Utility/ModuleSetupCode.c @@ -705,6 +705,13 @@ class __Pyx_FakeReference { #endif #define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj)) +#ifndef CO_COROUTINE + #define CO_COROUTINE 0x80 +#endif +#ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x200 +#endif + #ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 #endif diff --git a/tests/run/test_coroutines_pep492.pyx b/tests/run/test_coroutines_pep492.pyx index 2841d97af..3060ab704 100644 --- a/tests/run/test_coroutines_pep492.pyx +++ b/tests/run/test_coroutines_pep492.pyx @@ -14,7 +14,7 @@ import copy #import types import pickle import os.path -#import inspect +import inspect import unittest import warnings import contextlib @@ -754,7 +754,8 @@ class AsyncBadSyntaxTest(unittest.TestCase): async def g(): pass await z await = 1 - #self.assertTrue(inspect.iscoroutinefunction(f)) + if sys.version_info >= (3,10,6): + self.assertTrue(inspect.iscoroutinefunction(f)) class TokenizerRegrTest(unittest.TestCase): @@ -777,7 +778,8 @@ class TokenizerRegrTest(unittest.TestCase): exec(buf, ns, ns) self.assertEqual(ns['i499'](), 499) self.assertEqual(type(ns['foo']()).__name__, 'coroutine') - #self.assertTrue(inspect.iscoroutinefunction(ns['foo'])) + if sys.version_info >= (3,10,6): + self.assertTrue(inspect.iscoroutinefunction(ns['foo'])) class CoroutineTest(unittest.TestCase): |