mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
[3.6] bpo-30876: Relative import from unloaded package now reimports the package (GH-2639) (#2676)
instead of failing with SystemError.
Relative import from non-package now fails with ImportError rather than
SystemError.
(cherry picked from commit 8a9cd20edc
)
This commit is contained in:
parent
65de1f3672
commit
28343e3392
8 changed files with 381 additions and 379 deletions
|
@ -1345,7 +1345,6 @@ resolve_name(PyObject *name, PyObject *globals, int level)
|
|||
PyObject *abs_name;
|
||||
PyObject *package = NULL;
|
||||
PyObject *spec;
|
||||
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
||||
Py_ssize_t last_dot;
|
||||
PyObject *base;
|
||||
int level_up;
|
||||
|
@ -1449,12 +1448,6 @@ resolve_name(PyObject *name, PyObject *globals, int level)
|
|||
"attempted relative import with no known parent package");
|
||||
goto error;
|
||||
}
|
||||
else if (PyDict_GetItem(interp->modules, package) == NULL) {
|
||||
PyErr_Format(PyExc_SystemError,
|
||||
"Parent module %R not loaded, cannot perform relative "
|
||||
"import", package);
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (level_up = 1; level_up < level; level_up += 1) {
|
||||
last_dot = PyUnicode_FindChar(package, '.', 0, last_dot, -1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue