allow_descriptor_getattr -> allow_unsafe_interpreter_executions

This commit is contained in:
Dave Halter
2023-07-29 00:03:45 +02:00
parent 62cbcb0844
commit 8a4b079d0f
5 changed files with 10 additions and 6 deletions

View File

@@ -741,7 +741,8 @@ class Interpreter(Script):
super().__init__(code, environment=environment, project=project, **kwds) super().__init__(code, environment=environment, project=project, **kwds)
self.namespaces = namespaces 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 # Dynamic params search is important when we work on functions that are
# called by other pieces of code. However for interpreter completions # called by other pieces of code. However for interpreter completions
# this is not important at all, because the current code is always new # this is not important at all, because the current code is always new

View File

@@ -103,7 +103,7 @@ class InferenceState:
self.is_analysis = False self.is_analysis = False
self.project = project self.project = project
self.access_cache = {} self.access_cache = {}
self.allow_descriptor_getattr = False self.allow_unsafe_executions = False
self.flow_analysis_enabled = True self.flow_analysis_enabled = True
self.reset_recursion_limitations() self.reset_recursion_limitations()

View File

@@ -437,7 +437,7 @@ class CompiledValueFilter(AbstractFilter):
def get(self, name): def get(self, name):
access_handle = self.compiled_value.access_handle 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( return self._get(
name, name,
lambda name: access_handle.is_allowed_getattr(name, safe=safe), lambda name: access_handle.is_allowed_getattr(name, safe=safe),
@@ -464,7 +464,7 @@ class CompiledValueFilter(AbstractFilter):
return [] return []
if (is_descriptor or not has_attribute) \ 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)] return [self._get_cached_name(name, is_empty=True)]
if self.is_instance and not in_dir_callback(name): if self.is_instance and not in_dir_callback(name):

View File

@@ -143,10 +143,13 @@ This improves autocompletion for libraries that use ``setattr`` or
``globals()`` modifications a lot. ``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 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) 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`.
""" """
# ---------------- # ----------------

View File

@@ -222,7 +222,7 @@ def test__getattr__completions(allow_unsafe_getattr, class_is_findable):
@pytest.fixture(params=[False, True]) @pytest.fixture(params=[False, True])
def allow_unsafe_getattr(request, monkeypatch): 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 return request.param