Georg Brandl avatar 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)

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.
 
 		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';
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.