summaryrefslogtreecommitdiff
path: root/astroid/manager.py
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-08-12 23:19:16 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-08-12 23:19:16 +0300
commit99aaeff9eee6222bd248c4468a3bd25f6bc5d7c4 (patch)
treee0e842edaa33c455dfbf1aeca1e5ae8de5d835db /astroid/manager.py
parentee3d54581c036de6e147be8425bb448bd0ded79c (diff)
downloadastroid-99aaeff9eee6222bd248c4468a3bd25f6bc5d7c4.tar.gz
Big cleanup across the entire project
The cleanup consisted in a couple of changes: * import only modules, not objects, in order to not clutter the module namespace and to not leak accidentally objects which aren't public API for the said modules. * use two spaces between module level functions * move some mixins from astroid.node_classes in the proper order, starting at the left, not being last in the MRO.
Diffstat (limited to 'astroid/manager.py')
-rw-r--r--astroid/manager.py48
1 files changed, 25 insertions, 23 deletions
diff --git a/astroid/manager.py b/astroid/manager.py
index 90cc8e7..ba1746a 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -25,7 +25,7 @@ import imp
import os
import zipimport
-from astroid.exceptions import AstroidBuildingException
+from astroid import exceptions
from astroid import modutils
from astroid import transforms
@@ -86,8 +86,8 @@ class AstroidManager(object):
return AstroidBuilder(self).file_build(filepath, modname)
elif fallback and modname:
return self.ast_from_module_name(modname)
- raise AstroidBuildingException('unable to get astroid for file %s' %
- filepath)
+ raise exceptions.AstroidBuildingException(
+ 'unable to get astroid for file %s' % filepath)
def _build_stub_module(self, modname):
from astroid.builder import AstroidBuilder
@@ -125,18 +125,20 @@ class AstroidManager(object):
module = modutils.load_module_from_name(modname)
except Exception as ex:
msg = 'Unable to load module %s (%s)' % (modname, ex)
- raise AstroidBuildingException(msg)
+ raise exceptions.AstroidBuildingException(msg)
return self.ast_from_module(module, modname)
elif mp_type == imp.PY_COMPILED:
- raise AstroidBuildingException("Unable to load compiled module %s" % (modname,))
+ msg = "Unable to load compiled module %s" % (modname,)
+ raise exceptions.AstroidBuildingException(msg)
if filepath is None:
- raise AstroidBuildingException("Unable to load module %s" % (modname,))
+ msg = "Unable to load module %s" % (modname,)
+ raise exceptions.AstroidBuildingException(msg)
return self.ast_from_file(filepath, modname, fallback=False)
- except AstroidBuildingException as e:
+ except exceptions.AstroidBuildingException as e:
for hook in self._failed_import_hooks:
try:
return hook(modname)
- except AstroidBuildingException:
+ except exceptions.AstroidBuildingException:
pass
raise e
finally:
@@ -173,9 +175,9 @@ class AstroidManager(object):
modname.split('.'), context_file=contextfile)
except ImportError as ex:
msg = 'Unable to load module %s (%s)' % (modname, ex)
- value = AstroidBuildingException(msg)
+ value = exceptions.AstroidBuildingException(msg)
self._mod_file_cache[(modname, contextfile)] = value
- if isinstance(value, AstroidBuildingException):
+ if isinstance(value, exceptions.AstroidBuildingException):
raise value
return value
@@ -200,8 +202,8 @@ class AstroidManager(object):
try:
modname = klass.__module__
except AttributeError:
- raise AstroidBuildingException(
- 'Unable to get module for class %s' % safe_repr(klass))
+ msg = 'Unable to get module for class %s' % safe_repr(klass)
+ raise exceptions.AstroidBuildingException(msg)
modastroid = self.ast_from_module_name(modname)
return modastroid.getattr(klass.__name__)[0] # XXX
@@ -214,25 +216,25 @@ class AstroidManager(object):
try:
modname = klass.__module__
except AttributeError:
- raise AstroidBuildingException(
- 'Unable to get module for %s' % safe_repr(klass))
+ msg = 'Unable to get module for %s' % safe_repr(klass)
+ raise exceptions.AstroidBuildingException(msg)
except Exception as ex:
- raise AstroidBuildingException(
- 'Unexpected error while retrieving module for %s: %s'
- % (safe_repr(klass), ex))
+ msg = ('Unexpected error while retrieving module for %s: %s'
+ % (safe_repr(klass), ex))
+ raise exceptions.AstroidBuildingException(msg)
try:
name = klass.__name__
except AttributeError:
- raise AstroidBuildingException(
- 'Unable to get name for %s' % safe_repr(klass))
+ msg = 'Unable to get name for %s' % safe_repr(klass)
+ raise exceptions.AstroidBuildingException(msg)
except Exception as ex:
- raise AstroidBuildingException(
- 'Unexpected error while retrieving name for %s: %s'
- % (safe_repr(klass), ex))
+ exc = ('Unexpected error while retrieving name for %s: %s'
+ % (safe_repr(klass), ex))
+ raise exceptions.AstroidBuildingException(exc)
# take care, on living object __module__ is regularly wrong :(
modastroid = self.ast_from_module_name(modname)
if klass is obj:
- for infered in modastroid.igetattr(name, context):
+ for infered in modastroid.igetattr(name, context):
yield infered
else:
for infered in modastroid.igetattr(name, context):