summaryrefslogtreecommitdiff
path: root/astroid/exceptions.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-12-06 18:00:01 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-12-06 18:00:01 +0200
commitf77f5e36632bf6ea76d044bf14a132ff6e22dbfb (patch)
treef6a34d4946bb7c8f6052b9071dc9ba9930aecd79 /astroid/exceptions.py
parent853726a295a8b4000bbb7ff9032cd1573e5ddf6c (diff)
downloadastroid-git-f77f5e36632bf6ea76d044bf14a132ff6e22dbfb.tar.gz
relative_to_absolute_name will now raise TooManyLevelsError when a relative import is trying to access something beyond the top-level package.
Diffstat (limited to 'astroid/exceptions.py')
-rw-r--r--astroid/exceptions.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/astroid/exceptions.py b/astroid/exceptions.py
index 9d57058c..21e9b61f 100644
--- a/astroid/exceptions.py
+++ b/astroid/exceptions.py
@@ -58,6 +58,21 @@ class AstroidImportError(AstroidBuildingError):
"""Exception class used when a module can't be imported by astroid."""
+class TooManyLevelsError(AstroidImportError):
+ """Exception class which is raised when a relative import was beyond the top-level.
+
+ Standard attributes:
+ level: The level which was attempted.
+ name: the name of the module on which the relative import was attempted.
+ """
+ level = None
+ name = None
+
+ def __init__(self, message='Relative import with too many levels '
+ '({level}) for module {name!r}', **kws):
+ super(TooManyLevelsError, self).__init__(message, **kws)
+
+
class AstroidSyntaxError(AstroidBuildingError):
"""Exception class used when a module can't be parsed."""