[3.12] gh-104879: Fix TypeAliasType.__module__ in exec() (GH-104881) (#104890)

(cherry picked from commit fe77a99fc8)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-05-24 12:30:57 -07:00 committed by GitHub
parent 3d91d034a0
commit b670214636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
}