Skip to content

Commit

Permalink
allow_descriptor_getattr -> allow_unsafe_interpreter_executions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Jul 28, 2023
1 parent 62cbcb0 commit 8a4b079
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion jedi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ def __init__(self, code, namespaces, *, project=None, **kwds):
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
Expand Down
2 changes: 1 addition & 1 deletion jedi/inference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, project, environment=None, script_path=None):
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()
Expand Down
4 changes: 2 additions & 2 deletions jedi/inference/compiled/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def __init__(self, inference_state, compiled_value, is_instance=False):

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),
Expand All @@ -464,7 +464,7 @@ def _get(self, name, allowed_getattr_callback, in_dir_callback, check_has_attrib
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):
Expand Down
5 changes: 4 additions & 1 deletion jedi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@
``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`.
"""

# ----------------
Expand Down
2 changes: 1 addition & 1 deletion test/test_api/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __dir__(self):

@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


Expand Down

0 comments on commit 8a4b079

Please sign in to comment.