diff options
author | Andrew Haigh <hello@nelf.in> | 2021-06-08 01:05:59 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 17:05:59 +0200 |
commit | cf6528cbc158097c4903f0cab68242ff14bb591b (patch) | |
tree | 8cdc8beab6af265bddb13039c8a5e44bd47cd6db /astroid/helpers.py | |
parent | 85791635a24cd300434ab2fa31acf21835315227 (diff) | |
download | astroid-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.py | 2 |
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) |