Skip to content

Commit 05c1f14

Browse files
committed
Fix gen_is_coroutine for Python 3.13
1 parent 6d45f3c commit 05c1f14

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

mypyc/lib-rt/mypyc_util.h

+3
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@ static inline void CPyLong_SetUnsignedSize(PyLongObject *o, Py_ssize_t n) {
115115

116116
#endif
117117

118+
// Are we targeting Python 3.13 or newer?
119+
#define CPY_3_13_FEATURES (PY_VERSION_HEX >= 0x030d0000)
120+
118121
#endif

mypyc/lib-rt/pythonsupport.h

+24-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,30 @@ _CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
392392
_PyObject_CallMethodIdObjArgs((self), (name), (arg), NULL)
393393
#endif
394394

395-
#if CPY_3_12_FEATURES
395+
#if CPY_3_13_FEATURES
396+
397+
// These are copied from genobject.c in Python 3.13
398+
399+
/* Returns a borrowed reference */
400+
static inline PyCodeObject *
401+
_PyGen_GetCode(PyGenObject *gen) {
402+
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)(gen->gi_iframe);
403+
return _PyFrame_GetCode(frame);
404+
}
405+
406+
static int
407+
gen_is_coroutine(PyObject *o)
408+
{
409+
if (PyGen_CheckExact(o)) {
410+
PyCodeObject *code = _PyGen_GetCode((PyGenObject*)o);
411+
if (code->co_flags & CO_ITERABLE_COROUTINE) {
412+
return 1;
413+
}
414+
}
415+
return 0;
416+
}
417+
418+
#elif CPY_3_12_FEATURES
396419

397420
// These are copied from genobject.c in Python 3.12
398421

0 commit comments

Comments
 (0)