diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-08-12 23:19:16 +0300 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-08-12 23:19:16 +0300 |
commit | 99aaeff9eee6222bd248c4468a3bd25f6bc5d7c4 (patch) | |
tree | e0e842edaa33c455dfbf1aeca1e5ae8de5d835db /astroid/objects.py | |
parent | ee3d54581c036de6e147be8425bb448bd0ded79c (diff) | |
download | astroid-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/objects.py')
-rw-r--r-- | astroid/objects.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/astroid/objects.py b/astroid/objects.py index aeb4ecd..c2ac9a5 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -28,29 +28,26 @@ leads to an inferred FrozenSet: import six +from astroid import bases +from astroid import decorators +from astroid import exceptions from astroid import MANAGER -from astroid.bases import ( - BUILTINS, NodeNG, Instance, _infer_stmts, - BoundMethod, -) -from astroid.exceptions import ( - SuperError, SuperArgumentTypeError, - NotFoundError, MroError -) -from astroid.node_classes import const_factory -from astroid.scoped_nodes import Class, Function -from astroid.mixins import ParentAssignTypeMixin -from astroid.decorators import cachedproperty - - -class FrozenSet(NodeNG, Instance, ParentAssignTypeMixin): +from astroid import mixins +from astroid import node_classes +from astroid import scoped_nodes + + +BUILTINS = six.moves.builtins.__name__ + + +class FrozenSet(bases.NodeNG, bases.Instance, mixins.ParentAssignTypeMixin): """class representing a FrozenSet composite node""" def __init__(self, elts=None): if elts is None: self.elts = [] else: - self.elts = [const_factory(e) for e in elts] + self.elts = [node_classes.const_factory(e) for e in elts] def pytype(self): return '%s.frozenset' % BUILTINS @@ -61,7 +58,7 @@ class FrozenSet(NodeNG, Instance, ParentAssignTypeMixin): def _infer(self, context=None): yield self - @cachedproperty + @decorators.cachedproperty def _proxied(self): builtins = MANAGER.astroid_cache[BUILTINS] return builtins.getattr('frozenset')[0] @@ -70,7 +67,7 @@ class FrozenSet(NodeNG, Instance, ParentAssignTypeMixin): return bool(self.elts) -class Super(NodeNG): +class Super(bases.NodeNG): """Proxy class over a super call. This class offers almost the same behaviour as Python's super, @@ -101,31 +98,34 @@ class Super(NodeNG): def super_mro(self): """Get the MRO which will be used to lookup attributes in this super.""" - if not isinstance(self.mro_pointer, Class): - raise SuperArgumentTypeError("The first super argument must be type.") + if not isinstance(self.mro_pointer, scoped_nodes.Class): + raise exceptions.SuperArgumentTypeError( + "The first super argument must be type.") - if isinstance(self.type, Class): + if isinstance(self.type, scoped_nodes.Class): # `super(type, type)`, most likely in a class method. self._class_based = True mro_type = self.type else: mro_type = getattr(self.type, '_proxied', None) - if not isinstance(mro_type, (Instance, Class)): - raise SuperArgumentTypeError("super(type, obj): obj must be an " - "instance or subtype of type") + if not isinstance(mro_type, (bases.Instance, scoped_nodes.Class)): + raise exceptions.SuperArgumentTypeError( + "super(type, obj): obj must be an " + "instance or subtype of type") if not mro_type.newstyle: - raise SuperError("Unable to call super on old-style classes.") + raise exceptions.SuperError("Unable to call super on old-style classes.") mro = mro_type.mro() if self.mro_pointer not in mro: - raise SuperArgumentTypeError("super(type, obj): obj must be an " - "instance or subtype of type") + raise exceptions.SuperArgumentTypeError( + "super(type, obj): obj must be an " + "instance or subtype of type") index = mro.index(self.mro_pointer) return mro[index + 1:] - @cachedproperty + @decorators.cachedproperty def _proxied(self): builtins = MANAGER.astroid_cache[BUILTINS] return builtins.getattr('super')[0] @@ -151,10 +151,10 @@ class Super(NodeNG): try: mro = self.super_mro() - except (MroError, SuperError) as exc: + except (exceptions.MroError, exceptions.SuperError) as exc: # Don't let invalid MROs or invalid super calls # to leak out as is from this function. - six.raise_from(NotFoundError, exc) + six.raise_from(exceptions.NotFoundError, exc) found = False for cls in mro: @@ -162,24 +162,24 @@ class Super(NodeNG): continue found = True - for infered in _infer_stmts([cls[name]], context, frame=self): - if not isinstance(infered, Function): + for infered in bases._infer_stmts([cls[name]], context, frame=self): + if not isinstance(infered, scoped_nodes.Function): yield infered continue # We can obtain different descriptors from a super depending # on what we are accessing and where the super call is. if infered.type == 'classmethod': - yield BoundMethod(infered, cls) + yield bases.BoundMethod(infered, cls) elif self._scope.type == 'classmethod' and infered.type == 'method': yield infered elif self._class_based or infered.type == 'staticmethod': yield infered else: - yield BoundMethod(infered, cls) + yield bases.BoundMethod(infered, cls) if not found: - raise NotFoundError(name) + raise exceptions.NotFoundError(name) def getattr(self, name, context=None): return list(self.igetattr(name, context=context)) |