instance_allow_descriptor_getattr as public setting

This commit is contained in:
Patterson, Kevin R
2023-02-08 18:17:26 -06:00
parent aeadba7cad
commit fac0b7f068
3 changed files with 9 additions and 3 deletions

View File

@@ -708,7 +708,6 @@ class Interpreter(Script):
:param namespaces: A list of namespace dictionaries such as the one
returned by :func:`globals` and :func:`locals`.
"""
_allow_descriptor_getattr_default = True
def __init__(self, code, namespaces, *, project=None, **kwds):
try:
@@ -729,7 +728,7 @@ class Interpreter(Script):
super().__init__(code, environment=environment, project=project, **kwds)
self.namespaces = namespaces
self._inference_state.allow_descriptor_getattr = self._allow_descriptor_getattr_default
self._inference_state.allow_descriptor_getattr = settings.instance_allow_descriptor_getattr
@cache.memoize_method
def _get_module_context(self):

View File

@@ -143,6 +143,12 @@ This improves autocompletion for libraries that use ``setattr`` or
``globals()`` modifications a lot.
"""
instance_allow_descriptor_getattr = 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)
"""
# ----------------
# Caching Validity
# ----------------

View File

@@ -8,6 +8,7 @@ import typing
import pytest
import jedi
import jedi.settings
from jedi.inference.compiled import mixed
from importlib import import_module
@@ -219,7 +220,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.Interpreter, '_allow_descriptor_getattr_default', request.param)
monkeypatch.setattr(jedi.settings,'instance_allow_descriptor_getattr', request.param)
return request.param