mirror of https://github.com/python/cpython
bpo-40703: Let PyType_FromSpec() set "type.__module__" only if it is not set yet. (GH-20273)
This commit is contained in:
parent
ec88e1bca8
commit
24b8bad6d3
|
@ -0,0 +1,2 @@
|
|||
The PyType_FromSpec*() functions no longer overwrite the type's "__module__" attribute
|
||||
if it is set via "Py_tp_members" or "Py_tp_getset".
|
|
@ -3067,6 +3067,10 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
|
|||
}
|
||||
|
||||
/* Set type.__module__ */
|
||||
if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__) == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
goto fail;
|
||||
}
|
||||
s = strrchr(spec->name, '.');
|
||||
if (s != NULL) {
|
||||
int err;
|
||||
|
@ -3085,6 +3089,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
|
|||
spec->name))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return (PyObject*)res;
|
||||
|
||||
|
|
Loading…
Reference in New Issue