Merge pull request #1911 from krpatter-intc/allow_descriptor_getattr_official_support

Make allow_descriptor_getattr a non-private variable for more official
This commit is contained in:
Dave Halter
2023-02-10 22:30:33 +00:00
committed by GitHub
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 :param namespaces: A list of namespace dictionaries such as the one
returned by :func:`globals` and :func:`locals`. returned by :func:`globals` and :func:`locals`.
""" """
_allow_descriptor_getattr_default = True
def __init__(self, code, namespaces, *, project=None, **kwds): def __init__(self, code, namespaces, *, project=None, **kwds):
try: try:
@@ -729,7 +728,7 @@ 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 = self._allow_descriptor_getattr_default self._inference_state.allow_descriptor_getattr = settings.instance_allow_descriptor_getattr
@cache.memoize_method @cache.memoize_method
def _get_module_context(self): def _get_module_context(self):

View File

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

View File

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