summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thénault <sylvain.thenault@logilab.fr>2009-03-18 11:14:38 +0100
committerSylvain Thénault <sylvain.thenault@logilab.fr>2009-03-18 11:14:38 +0100
commitdafc8c716aedb846f3aee4fd13b5d71fcf4430d4 (patch)
tree09ca3bf53f7da7a7ee4cf99626f3447563ebb12f
parenta4e3901403aa98c112c268e60d1ed2029d5041d3 (diff)
downloadastroid-git-dafc8c716aedb846f3aee4fd13b5d71fcf4430d4.tar.gz
always propagate context to avoid infinite loops
--HG-- branch : _ast_compat
-rw-r--r--inference.py6
-rw-r--r--protocols.py20
2 files changed, 13 insertions, 13 deletions
diff --git a/inference.py b/inference.py
index 0c6ee1dc..51dd06b2 100644
--- a/inference.py
+++ b/inference.py
@@ -122,7 +122,7 @@ class CallContext:
its.append((YES,))
continue
try:
- its.append(infered.getitem(argindex).infer(context))
+ its.append(infered.getitem(argindex, context).infer(context))
except (InferenceError, AttributeError):
its.append((YES,))
except (IndexError, TypeError):
@@ -137,7 +137,7 @@ class CallContext:
its.append((YES,))
continue
try:
- its.append(infered.getitem(name).infer(context))
+ its.append(infered.getitem(name, context).infer(context))
except (InferenceError, AttributeError):
its.append((YES,))
except (IndexError, TypeError):
@@ -298,7 +298,7 @@ def infer_subscript(self, context=None):
return
try:
# suppose it's a Tuple/List node (attribute error else)
- assigned = self.expr.getitem(index.value)
+ assigned = self.expr.getitem(index.value, context)
except AttributeError:
raise InferenceError()
except (IndexError, TypeError):
diff --git a/protocols.py b/protocols.py
index eb9fcc37..d7cb0e3e 100644
--- a/protocols.py
+++ b/protocols.py
@@ -95,16 +95,16 @@ nodes.Const.infer_binary_op = yes_if_nothing_infered(const_infer_binary_op)
def tl_infer_binary_op(self, operator, other, context):
- for other in other.infer():
+ for other in other.infer(context):
if isinstance(other, self.__class__) and operator == '+':
node = self.__class__()
- elts = [n for elt in self.elts for n in elt.infer()]
- elts += [n for elt in other.elts for n in elt.infer()]
+ elts = [n for elt in self.elts for n in elt.infer(context)]
+ elts += [n for elt in other.elts for n in elt.infer(context)]
node.elts = elts
yield node
elif isinstance(other, Const) and operator == '*':
node = self.__class__()
- elts = [n for elt in self.elts for n in elt.infer()] * other.value
+ elts = [n for elt in self.elts for n in elt.infer(context)] * other.value
node.elts = elts
yield node
elif isinstance(other, Instance) and not isinstance(other, Const):
@@ -151,7 +151,7 @@ def _resolve_looppart(parts, asspath, context):
continue # XXX log error
for stmt in part.itered():
try:
- assigned = stmt.getitem(index)
+ assigned = stmt.getitem(index, context)
except (AttributeError, IndexError):
continue
if not asspath:
@@ -262,7 +262,7 @@ def _resolve_asspart(parts, asspath, context):
for part in parts:
if hasattr(part, 'getitem'):
try:
- assigned = part.getitem(index)
+ assigned = part.getitem(index, context)
# XXX raise a specific exception to avoid potential hiding of
# unexpected exception ?
except (TypeError, IndexError):
@@ -399,22 +399,22 @@ nodes.Dict.itered = dict_itered
# subscription protocol #######################################################
-def const_getitem(self, index):
+def const_getitem(self, index, context=None):
if isinstance(self.value, basestring):
return self.value[index]
raise TypeError()
nodes.Const.getitem = const_getitem
-def tl_getitem(self, index):
+def tl_getitem(self, index, context=None):
return self.elts[index]
nodes.Tuple.getitem = tl_getitem
nodes.List.getitem = tl_getitem
-def dict_getitem(self, key):
+def dict_getitem(self, key, context=None):
for i in xrange(0, len(self.items), 2):
- for inferedkey in self.items[i].infer():
+ for inferedkey in self.items[i].infer(context):
if inferedkey is YES:
continue
if isinstance(inferedkey, Const) and inferedkey.value == key: