summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-03-04 16:51:48 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-03-04 16:51:48 +0100
commitd55bb67c935abc13f77694da999499e1460682cd (patch)
tree815bed7bac0ccb68d2b2d218cfb30a1d9211059e
parent917ce1406d94881031cccf88bbe9f78a0e4c2a95 (diff)
downloadastroid-d55bb67c935abc13f77694da999499e1460682cd.tar.gz
add a "has_base method" for Class to break circular imports and more polymorphism.
of course all other nodes return 'False'.
-rw-r--r--bases.py3
-rw-r--r--scoped_nodes.py15
2 files changed, 15 insertions, 3 deletions
diff --git a/bases.py b/bases.py
index 248d16a..e78b4b4 100644
--- a/bases.py
+++ b/bases.py
@@ -525,6 +525,9 @@ class NodeNG(BaseClass):
"""instanciate a node if it is a Class node, else return self"""
return self
+ def has_base(self, node):
+ return False
+
def callable(self):
return False
diff --git a/scoped_nodes.py b/scoped_nodes.py
index 1b16f47..a40de8c 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -145,11 +145,13 @@ class LookupMixIn(BaseClass):
# line filtering is on and we have reached our location, break
if mylineno > 0 and stmt.fromlineno > mylineno:
break
- if isinstance(node, Class) and self in node.bases:
- break
assert hasattr(node, 'ass_type'), (node, node.scope(),
node.scope().locals)
ass_type = node.ass_type()
+
+ if node.has_base(self):
+ break
+
if ass_type is mystmt and not isinstance(ass_type, (Class,
Function, Import, From, Lambda)):
if not isinstance(ass_type, Comprehension):
@@ -161,7 +163,9 @@ class LookupMixIn(BaseClass):
# original node's statement is the assignment, only keeps
# current node (gen exp, list comp)
_stmts = [node]
- break
+ break
+
+
optional_assign = isinstance(ass_type, (For, Comprehension))
if optional_assign and ass_type.parent_of(self):
# we are inside a loop, loop var assigment is hidding previous
@@ -169,6 +173,7 @@ class LookupMixIn(BaseClass):
_stmts = [node]
_stmt_parents = [stmt.parent]
continue
+
# XXX comment various branches below!!!
try:
pindex = _stmt_parents.index(stmt.parent)
@@ -225,6 +230,7 @@ def builtin_lookup(name):
return the list of matching statements and the astng for the builtin
module
"""
+ # TODO : once there is no more monkey patching, make a BUILTINASTNG const
builtinastng = MANAGER.astng_from_module(__builtin__)
if name == '__dict__':
return builtinastng, ()
@@ -908,6 +914,9 @@ class Class(StmtMixIn, LocalsDictNodeNG):
if astng.instance_attrs.has_key(name):
yield astng
+ def has_base(self, node):
+ return node in self.bases
+
def local_attr(self, name, context=None):
"""return the list of assign node associated to name in this class
locals or in its parents