Commits

Georg Brandl committed 8394d2e

Bug #1550983: emit better error messages for erroneous relative
imports (if not in package and if beyond toplevel package).
(backport from rev. 51765)

  • Participants
  • Parent commits ae5b8a8
  • Branches 2.5

Comments (0)

Files changed (2)

 Core and builtins
 -----------------
 
+- Bug #1550983: emit better error messages for erroneous relative
+  imports (if not in package and if beyond toplevel package).
+
 - Overflow checking code in integer division ran afoul of new gcc
   optimizations.  Changed to be more standard-conforming.
 

File Python/import.c

 		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)
 		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';