summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2020-06-10 16:09:01 (GMT)
committerGitHub <noreply@github.com>2020-06-10 16:09:01 (GMT)
commit24b8bad6d30ae4fb37ee686a073adfa5308659f9 (patch)
tree31e77aa0061179f134284fd8e0a984a53b91585d /Objects
parentec88e1bca81a167e6d5c0ac635e22f84298cb1df (diff)
downloadcpython-24b8bad6d30ae4fb37ee686a073adfa5308659f9.zip
cpython-24b8bad6d30ae4fb37ee686a073adfa5308659f9.tar.gz
cpython-24b8bad6d30ae4fb37ee686a073adfa5308659f9.tar.bz2
bpo-40703: Let PyType_FromSpec() set "type.__module__" only if it is not set yet. (GH-20273)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1d556e9..c8f0d2e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3067,23 +3067,28 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
}
/* Set type.__module__ */
- s = strrchr(spec->name, '.');
- if (s != NULL) {
- int err;
- modname = PyUnicode_FromStringAndSize(
- spec->name, (Py_ssize_t)(s - spec->name));
- if (modname == NULL) {
+ if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__) == NULL) {
+ if (PyErr_Occurred()) {
goto fail;
}
- err = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname);
- Py_DECREF(modname);
- if (err != 0)
- goto fail;
- } else {
- if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
- "builtin type %.200s has no __module__ attribute",
- spec->name))
- goto fail;
+ s = strrchr(spec->name, '.');
+ if (s != NULL) {
+ int err;
+ modname = PyUnicode_FromStringAndSize(
+ spec->name, (Py_ssize_t)(s - spec->name));
+ if (modname == NULL) {
+ goto fail;
+ }
+ err = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname);
+ Py_DECREF(modname);
+ if (err != 0)
+ goto fail;
+ } else {
+ if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
+ "builtin type %.200s has no __module__ attribute",
+ spec->name))
+ goto fail;
+ }
}
return (PyObject*)res;