Skip to content

Commit efe84d4

Browse files
authored
[mypyc] Fix generators on Python 3.12 (#15472)
I think we relied on undocumented behavior on older Python versions. Now it works consistently across all supported Python versions. Work on mypyc/mypyc#995.
1 parent c2dc3ff commit efe84d4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mypyc/lib-rt/exc_ops.c

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ void CPy_Reraise(void) {
2424
}
2525

2626
void CPyErr_SetObjectAndTraceback(PyObject *type, PyObject *value, PyObject *traceback) {
27+
if (!PyType_Check(type) && value == Py_None) {
28+
// The first argument must be an exception instance
29+
value = type;
30+
type = (PyObject *)Py_TYPE(value);
31+
}
32+
2733
// Set the value and traceback of an error. Because calling
2834
// PyErr_Restore takes away a reference to each object passed in
2935
// as an argument, we manually increase the reference count of

0 commit comments

Comments
 (0)