From 1947e7dd56a26b4cbe4882cb98ed360420df2d0c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 27 Jul 2023 13:48:53 +0200 Subject: [PATCH] Avoid dynamic params search for Interpreter, fixes #1899 --- jedi/api/__init__.py | 8 ++++++++ jedi/inference/__init__.py | 1 + jedi/inference/dynamic_params.py | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 1428eb04..33b9f50e 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -742,6 +742,14 @@ class Interpreter(Script): self.namespaces = namespaces self._inference_state.allow_descriptor_getattr = settings.instance_allow_descriptor_getattr + # Dynamic params search is important when we work on functions that are + # called by other pieces of code. However for interpreter completions + # this is not important at all, because the current code is always new + # and will never be called by something. + # Also sometimes this logic goes a bit too far like in + # https://github.com/ipython/ipython/issues/13866, where it takes + # seconds to do a simple completion. + self._inference_state.do_dynamic_params_search = False @cache.memoize_method def _get_module_context(self): diff --git a/jedi/inference/__init__.py b/jedi/inference/__init__.py index adf8531f..3a8735fa 100644 --- a/jedi/inference/__init__.py +++ b/jedi/inference/__init__.py @@ -99,6 +99,7 @@ class InferenceState: self.mixed_cache = {} # see `inference.compiled.mixed._create()` self.analysis = [] self.dynamic_params_depth = 0 + self.do_dynamic_params_search = settings.dynamic_params self.is_analysis = False self.project = project self.access_cache = {} diff --git a/jedi/inference/dynamic_params.py b/jedi/inference/dynamic_params.py index c47d4dae..e759111a 100644 --- a/jedi/inference/dynamic_params.py +++ b/jedi/inference/dynamic_params.py @@ -66,11 +66,11 @@ def dynamic_param_lookup(function_value, param_index): have to look for all calls to ``func`` to find out what ``foo`` possibly is. """ - funcdef = function_value.tree_node - - if not settings.dynamic_params: + if not function_value.inference_state.do_dynamic_params_search: return NO_VALUES + funcdef = function_value.tree_node + path = function_value.get_root_context().py__file__() if path is not None and is_stdlib_path(path): # We don't want to search for references in the stdlib. Usually people