From 8a4b079d0f887648ce2e50dbe04c5c5301f4b01e Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 29 Jul 2023 00:03:45 +0200 Subject: [PATCH] allow_descriptor_getattr -> allow_unsafe_interpreter_executions --- jedi/api/__init__.py | 3 ++- jedi/inference/__init__.py | 2 +- jedi/inference/compiled/value.py | 4 ++-- jedi/settings.py | 5 ++++- test/test_api/test_interpreter.py | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 33b9f50e..9620ea71 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -741,7 +741,8 @@ class Interpreter(Script): super().__init__(code, environment=environment, project=project, **kwds) self.namespaces = namespaces - self._inference_state.allow_descriptor_getattr = settings.instance_allow_descriptor_getattr + self._inference_state.allow_unsafe_executions = \ + settings.allow_unsafe_interpreter_executions # 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 diff --git a/jedi/inference/__init__.py b/jedi/inference/__init__.py index 3a8735fa..7ebeb79f 100644 --- a/jedi/inference/__init__.py +++ b/jedi/inference/__init__.py @@ -103,7 +103,7 @@ class InferenceState: self.is_analysis = False self.project = project self.access_cache = {} - self.allow_descriptor_getattr = False + self.allow_unsafe_executions = False self.flow_analysis_enabled = True self.reset_recursion_limitations() diff --git a/jedi/inference/compiled/value.py b/jedi/inference/compiled/value.py index 2d5323ad..48a1c01e 100644 --- a/jedi/inference/compiled/value.py +++ b/jedi/inference/compiled/value.py @@ -437,7 +437,7 @@ class CompiledValueFilter(AbstractFilter): def get(self, name): access_handle = self.compiled_value.access_handle - safe = not self._inference_state.allow_descriptor_getattr + safe = not self._inference_state.allow_unsafe_executions return self._get( name, lambda name: access_handle.is_allowed_getattr(name, safe=safe), @@ -464,7 +464,7 @@ class CompiledValueFilter(AbstractFilter): return [] if (is_descriptor or not has_attribute) \ - and not self._inference_state.allow_descriptor_getattr: + and not self._inference_state.allow_unsafe_executions: return [self._get_cached_name(name, is_empty=True)] if self.is_instance and not in_dir_callback(name): diff --git a/jedi/settings.py b/jedi/settings.py index 383ee7cb..3a333e01 100644 --- a/jedi/settings.py +++ b/jedi/settings.py @@ -143,10 +143,13 @@ This improves autocompletion for libraries that use ``setattr`` or ``globals()`` modifications a lot. """ -instance_allow_descriptor_getattr = True +allow_unsafe_interpreter_executions = True """ Controls whether descriptors are evaluated when using an Interpreter. This is something you might want to control when using Jedi from a Repl (e.g. IPython) + +Generally this setting allows Jedi to execute __getitem__ and descriptors like +`property`. """ # ---------------- diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index 43042210..82a40b8e 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -222,7 +222,7 @@ def test__getattr__completions(allow_unsafe_getattr, class_is_findable): @pytest.fixture(params=[False, True]) def allow_unsafe_getattr(request, monkeypatch): - monkeypatch.setattr(jedi.settings,'instance_allow_descriptor_getattr', request.param) + monkeypatch.setattr(jedi.settings, 'allow_unsafe_interpreter_executions', request.param) return request.param