Bug #1550983: emit better error messages for erroneous relative
imports (if not in package and if beyond toplevel package).
(backport from rev. 51765)
diff --git a/Python/import.c b/Python/import.c
index a0c5055..5af3651 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2114,7 +2114,7 @@
size_t len;
if (lastdot == NULL && level > 0) {
PyErr_SetString(PyExc_ValueError,
- "Relative importpath too deep");
+ "Attempted relative import in non-package");
return NULL;
}
if (lastdot == NULL)
@@ -2133,7 +2133,8 @@
char *dot = strrchr(buf, '.');
if (dot == NULL) {
PyErr_SetString(PyExc_ValueError,
- "Relative importpath too deep");
+ "Attempted relative import beyond "
+ "toplevel package");
return NULL;
}
*dot = '\0';