summaryrefslogtreecommitdiff
path: root/Python/import.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/Python/import.c b/Python/import.c
index ab7db6bc17..495012d1c7 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1601,22 +1601,20 @@ resolve_name(PyObject *name, PyObject *globals, int level)
if (dot == -2) {
goto error;
}
-
- if (dot >= 0) {
- PyObject *substr = PyUnicode_Substring(package, 0, dot);
- if (substr == NULL) {
- goto error;
- }
- Py_SETREF(package, substr);
+ else if (dot == -1) {
+ goto no_parent_error;
}
+ PyObject *substr = PyUnicode_Substring(package, 0, dot);
+ if (substr == NULL) {
+ goto error;
+ }
+ Py_SETREF(package, substr);
}
}
last_dot = PyUnicode_GET_LENGTH(package);
if (last_dot == 0) {
- PyErr_SetString(PyExc_ImportError,
- "attempted relative import with no known parent package");
- goto error;
+ goto no_parent_error;
}
for (level_up = 1; level_up < level; level_up += 1) {
@@ -1642,6 +1640,11 @@ resolve_name(PyObject *name, PyObject *globals, int level)
Py_DECREF(base);
return abs_name;
+ no_parent_error:
+ PyErr_SetString(PyExc_ImportError,
+ "attempted relative import "
+ "with no known parent package");
+
error:
Py_XDECREF(package);
return NULL;