summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2019-12-30 13:42:18 +0100
committerhippo91 <guillaume.peillex@gmail.com>2019-12-30 13:42:18 +0100
commitcc3bfc5dc94062a582b7b3226598f09d7ec7044e (patch)
tree2ac2c3d5e316d31ae5a67d29782f3917d0a9c951
parent4fc45c581523e4883937e1b7a5314e434e8f3125 (diff)
downloadastroid-git-cc3bfc5dc94062a582b7b3226598f09d7ec7044e.tar.gz
Turns the context.path from a set to a dict which values are the number of times the node has been visited. The push method return True depending on a condition of the number of visits.
-rw-r--r--astroid/context.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/astroid/context.py b/astroid/context.py
index 70a92088..113cac6b 100644
--- a/astroid/context.py
+++ b/astroid/context.py
@@ -28,8 +28,10 @@ class InferenceContext:
"extra_context",
)
+ maximum_path_visit = 3
+
def __init__(self, path=None, inferred=None):
- self.path = path or set()
+ self.path = path or dict()
"""
:type: set(tuple(NodeNG, optional(str)))
@@ -86,10 +88,10 @@ class InferenceContext:
Allows one to see if the given node has already
been looked at for this inference context"""
name = self.lookupname
- if (node, name) in self.path:
+ if self.path.get((node, name), 0) >= self.maximum_path_visit:
return True
- self.path.add((node, name))
+ self.path[(node, name)] = self.path.setdefault((node, name), 0) + 1
return False
def clone(self):
@@ -118,7 +120,7 @@ class InferenceContext:
@contextlib.contextmanager
def restore_path(self):
- path = set(self.path)
+ path = dict(self.path)
yield
self.path = path