summaryrefslogtreecommitdiff
path: root/node_classes.py
diff options
context:
space:
mode:
Diffstat (limited to 'node_classes.py')
-rw-r--r--node_classes.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/node_classes.py b/node_classes.py
index b92fc247..13376d11 100644
--- a/node_classes.py
+++ b/node_classes.py
@@ -20,6 +20,8 @@
import sys
+from logilab.common.decorators import cachedproperty
+
from astroid.exceptions import NoDefault
from astroid.bases import (NodeNG, Statement, Instance, InferenceContext,
_infer_stmts, YES, BUILTINS)
@@ -127,8 +129,7 @@ class LookupMixIn(object):
the lookup method
"""
frame, stmts = self.lookup(name)
- context = InferenceContext()
- return _infer_stmts(stmts, context, frame)
+ return _infer_stmts(stmts, None, frame)
def _filter_stmts(self, stmts, frame, offset):
"""filter statements to remove ignorable statements.
@@ -303,6 +304,11 @@ class Arguments(NodeNG, AssignTypeMixin):
return name
return None
+ @cachedproperty
+ def fromlineno(self):
+ lineno = super(Arguments, self).fromlineno
+ return max(lineno, self.parent.fromlineno)
+
def format_args(self):
"""return arguments formatted as string"""
result = []
@@ -597,7 +603,8 @@ class ExceptHandler(Statement, AssignTypeMixin):
name = None
body = None
- def _blockstart_toline(self):
+ @cachedproperty
+ def blockstart_tolineno(self):
if self.name:
return self.name.tolineno
elif self.type:
@@ -605,11 +612,6 @@ class ExceptHandler(Statement, AssignTypeMixin):
else:
return self.lineno
- def set_line_info(self, lastchild):
- self.fromlineno = self.lineno
- self.tolineno = lastchild.tolineno
- self.blockstart_tolineno = self._blockstart_toline()
-
def catch(self, exceptions):
if self.type is None or exceptions is None:
return True
@@ -640,7 +642,8 @@ class For(BlockRangeMixIn, AssignTypeMixin, Statement):
orelse = None
optional_assign = True
- def _blockstart_toline(self):
+ @cachedproperty
+ def blockstart_tolineno(self):
return self.iter.tolineno
@@ -675,7 +678,8 @@ class If(BlockRangeMixIn, Statement):
body = None
orelse = None
- def _blockstart_toline(self):
+ @cachedproperty
+ def blockstart_tolineno(self):
return self.test.tolineno
def block_range(self, lineno):
@@ -826,9 +830,6 @@ class TryExcept(BlockRangeMixIn, Statement):
def _infer_name(self, frame, name):
return name
- def _blockstart_toline(self):
- return self.lineno
-
def block_range(self, lineno):
"""handle block line numbers range for try/except statements"""
last = None
@@ -848,9 +849,6 @@ class TryFinally(BlockRangeMixIn, Statement):
body = None
finalbody = None
- def _blockstart_toline(self):
- return self.lineno
-
def block_range(self, lineno):
"""handle block line numbers range for try/finally statements"""
child = self.body[0]
@@ -894,7 +892,8 @@ class While(BlockRangeMixIn, Statement):
body = None
orelse = None
- def _blockstart_toline(self):
+ @cachedproperty
+ def blockstart_tolineno(self):
return self.test.tolineno
def block_range(self, lineno):
@@ -908,7 +907,8 @@ class With(BlockRangeMixIn, AssignTypeMixin, Statement):
items = None
body = None
- def _blockstart_toline(self):
+ @cachedproperty
+ def blockstart_tolineno(self):
return self.items[-1][0].tolineno
def get_children(self):