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
commit7c7aa15f200df3e4ab7b83aa8402ddcfb7458846 (patch)
treec95f6b112a0447669de214fa9d3f517a21e05124 /astroid/exceptions.py
parent433a5b874cb8bff40c26451a75586be512707bab (diff)
downloadastroid-git-7c7aa15f200df3e4ab7b83aa8402ddcfb7458846.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 993e4b15..3cfadbd2 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."""