summaryrefslogtreecommitdiff
path: root/astroid/node_classes.py
diff options
context:
space:
mode:
authorBryce Guinta <bryce.guinta@protonmail.com>2020-06-22 02:22:16 -0400
committerGitHub <noreply@github.com>2020-06-22 08:22:16 +0200
commit4b7566b0c8365613198af493d4115d32d7d4c66e (patch)
tree57ab0d0b8f2166ffdff34797c5710f64251142ef /astroid/node_classes.py
parent184b591ec79468d75be03835ee0d6fd12343d93a (diff)
downloadastroid-git-4b7566b0c8365613198af493d4115d32d7d4c66e.tar.gz
Squash one-off inference utility functions to help reduce recursion errors (#804)
This also makes debugging a lot simpler reducing the complexity of the function stack.
Diffstat (limited to 'astroid/node_classes.py')
-rw-r--r--astroid/node_classes.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index 59b1e31c..e9d75d79 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -354,19 +354,37 @@ class NodeNG:
# explicit_inference is not bound, give it self explicitly
try:
# pylint: disable=not-callable
- return self._explicit_inference(self, context, **kwargs)
+ yield from self._explicit_inference(self, context, **kwargs)
+ return
except exceptions.UseInferenceDefault:
pass
if not context:
- return self._infer(context, **kwargs)
+ yield from self._infer(context, **kwargs)
+ return
key = (self, context.lookupname, context.callcontext, context.boundnode)
if key in context.inferred:
- return iter(context.inferred[key])
+ yield from context.inferred[key]
+ return
+
+ generator = self._infer(context, **kwargs)
+ results = []
+
+ # Limit inference amount to help with performance issues with
+ # exponentially exploding possible results.
+ limit = MANAGER.max_inferable_values
+ for i, result in enumerate(generator):
+ if i >= limit:
+ yield util.Uninferable
+ break
+ results.append(result)
+ yield result
- gen = context.cache_generator(key, self._infer(context, **kwargs))
- return util.limit_inference(gen, MANAGER.max_inferable_values)
+ # Cache generated results for subsequent inferences of the
+ # same node using the same context
+ context.inferred[key] = tuple(results)
+ return
def _repr_name(self):
"""Get a name for nice representation.