gh-104879: Fix TypeAliasType.__module__ in exec() (#104881)

This commit is contained in:
Jelle Zijlstra
2023-05-24 11:48:13 -07:00
committed by GitHub
parent 1497607a8e
commit fe77a99fc8
4 changed files with 52 additions and 2 deletions

View File

@@ -1319,8 +1319,13 @@ typealias_module(PyObject *self, void *unused)
return Py_NewRef(ta->module);
}
if (ta->compute_value != NULL) {
// PyFunction_GetModule() returns a borrowed reference
return Py_NewRef(PyFunction_GetModule(ta->compute_value));
PyObject* mod = PyFunction_GetModule(ta->compute_value);
if (mod != NULL) {
// PyFunction_GetModule() returns a borrowed reference,
// and it may return NULL (e.g., for functions defined
// in an exec()'ed block).
return Py_NewRef(mod);
}
}
Py_RETURN_NONE;
}