summaryrefslogtreecommitdiff
path: root/astroid/helpers.py
diff options
context:
space:
mode:
authorAndrew Haigh <hello@nelf.in>2021-06-08 01:05:59 +1000
committerGitHub <noreply@github.com>2021-06-07 17:05:59 +0200
commitcf6528cbc158097c4903f0cab68242ff14bb591b (patch)
tree8cdc8beab6af265bddb13039c8a5e44bd47cd6db /astroid/helpers.py
parent85791635a24cd300434ab2fa31acf21835315227 (diff)
downloadastroid-git-cf6528cbc158097c4903f0cab68242ff14bb591b.tar.gz
Performance improvements to counter context.clone slowdown (#1009)
* Add limit to the total number of nodes inferred per context This change abuses mutable references to create a sort of interior mutable cell shared between a context and all of its clones. The idea is that when a node is inferred at the toplevel, it is called with context = None, creating a new InferenceContext and starting a count from zero. However, when a context is cloned we re-use the cell and cause the count in the "parent" context to be incremented when nodes are inferred in the "child" context. * Add global inference cache * Update safe_infer to catch StopIteration
Diffstat (limited to 'astroid/helpers.py')
-rw-r--r--astroid/helpers.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/astroid/helpers.py b/astroid/helpers.py
index cb16ecdc..db86606e 100644
--- a/astroid/helpers.py
+++ b/astroid/helpers.py
@@ -150,7 +150,7 @@ def safe_infer(node, context=None):
try:
inferit = node.infer(context=context)
value = next(inferit)
- except exceptions.InferenceError:
+ except (exceptions.InferenceError, StopIteration):
return None
try:
next(inferit)