summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2023-05-24 18:48:13 (GMT)
committerGitHub <noreply@github.com>2023-05-24 18:48:13 (GMT)
commitfe77a99fc8b549a8bf9ccbc5485fe5ea9bcf47b9 (patch)
tree0f5fab670bfe697e91f64962b5f7dbbcd71befb9 /Objects
parent1497607a8e99f1103c40368dd5f9057f0146a520 (diff)
downloadcpython-fe77a99fc8b549a8bf9ccbc5485fe5ea9bcf47b9.zip
cpython-fe77a99fc8b549a8bf9ccbc5485fe5ea9bcf47b9.tar.gz
cpython-fe77a99fc8b549a8bf9ccbc5485fe5ea9bcf47b9.tar.bz2
gh-104879: Fix TypeAliasType.__module__ in exec() (#104881)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typevarobject.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c
index 6730ebf..6aa0d8a 100644
--- a/Objects/typevarobject.c
+++ b/Objects/typevarobject.c
@@ -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;
}