mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
Being able to overload a sys.module entry during import of a module was broken by this changeset.
This commit is contained in:
parent
da20cd2b6b
commit
d76bc7abac
5 changed files with 504 additions and 498 deletions
|
@ -2447,22 +2447,15 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
|
|||
Py_DECREF(partition);
|
||||
|
||||
if (level == 0) {
|
||||
if (PyUnicode_GET_LENGTH(name) ==
|
||||
PyUnicode_GET_LENGTH(front)) {
|
||||
final_mod = mod;
|
||||
}
|
||||
else {
|
||||
final_mod = PyDict_GetItem(interp->modules, front);
|
||||
if (final_mod == NULL) {
|
||||
PyErr_Format(PyExc_KeyError,
|
||||
"%R not in sys.modules as expected", front);
|
||||
}
|
||||
}
|
||||
final_mod = PyDict_GetItem(interp->modules, front);
|
||||
Py_DECREF(front);
|
||||
if (final_mod == NULL) {
|
||||
goto error_with_unlock;
|
||||
PyErr_Format(PyExc_KeyError,
|
||||
"%R not in sys.modules as expected", front);
|
||||
}
|
||||
else {
|
||||
Py_INCREF(final_mod);
|
||||
}
|
||||
Py_INCREF(final_mod);
|
||||
}
|
||||
else {
|
||||
Py_ssize_t cut_off = PyUnicode_GET_LENGTH(name) -
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue