From cf6528cbc158097c4903f0cab68242ff14bb591b Mon Sep 17 00:00:00 2001 From: Andrew Haigh Date: Tue, 8 Jun 2021 01:05:59 +1000 Subject: 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 --- astroid/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'astroid/helpers.py') 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) -- cgit v1.2.1