From 37a9e579ec8eab67e9e73e074deb8900ac72c744 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 6 Sep 2006 06:09:34 +0000 Subject: [PATCH] Bug #1550983: emit better error messages for erroneous relative imports (if not in package and if beyond toplevel package). (backport from rev. 51765) --- Misc/NEWS | 3 +++ Python/import.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index fe0308742d..ceb26a1094 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,9 @@ What's New in Python 2.5 release candidate 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. diff --git a/Python/import.c b/Python/import.c index a0c5055142..5af365187e 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2114,7 +2114,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level) 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 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level) 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'; -- 2.40.0