forked from VimPlug/jedi
Fix stub lookups for MixedObject
This commit is contained in:
@@ -47,9 +47,7 @@ class MixedObject(ContextWrapper):
|
|||||||
yield MixedObjectFilter(self.evaluator, self)
|
yield MixedObjectFilter(self.evaluator, self)
|
||||||
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
print(self._wrapped_context)
|
return (to_stub(self._wrapped_context) or self._wrapped_context).py__call__(arguments)
|
||||||
print(to_stub(self._wrapped_context))
|
|
||||||
return self._wrapped_context.py__call__(arguments)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (
|
return '<%s: %s>' % (
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import re
|
|||||||
from jedi.file_io import FileIO
|
from jedi.file_io import FileIO
|
||||||
from jedi._compatibility import FileNotFoundError, cast_path
|
from jedi._compatibility import FileNotFoundError, cast_path
|
||||||
from jedi.parser_utils import get_cached_code_lines
|
from jedi.parser_utils import get_cached_code_lines
|
||||||
from jedi.evaluate.base_context import ContextSet
|
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
||||||
from jedi.evaluate.gradual.stub_context import TypingModuleWrapper, StubModuleContext
|
from jedi.evaluate.gradual.stub_context import TypingModuleWrapper, StubModuleContext
|
||||||
|
|
||||||
_jedi_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
_jedi_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
@@ -124,6 +124,8 @@ def _try_to_load_stub_cached(evaluator, import_names, *args, **kwargs):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# TODO is this needed? where are the exceptions coming from that make this
|
||||||
|
# necessary? Just remove this line.
|
||||||
evaluator.stub_module_cache[import_names] = None
|
evaluator.stub_module_cache[import_names] = None
|
||||||
evaluator.stub_module_cache[import_names] = result = \
|
evaluator.stub_module_cache[import_names] = result = \
|
||||||
_try_to_load_stub(evaluator, import_names, *args, **kwargs)
|
_try_to_load_stub(evaluator, import_names, *args, **kwargs)
|
||||||
@@ -138,8 +140,16 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
This is modelled to work like "PEP 561 -- Distributing and Packaging Type
|
This is modelled to work like "PEP 561 -- Distributing and Packaging Type
|
||||||
Information", see https://www.python.org/dev/peps/pep-0561.
|
Information", see https://www.python.org/dev/peps/pep-0561.
|
||||||
"""
|
"""
|
||||||
|
if parent_module_context is None and len(import_names) > 1:
|
||||||
|
try:
|
||||||
|
parent_module_context = _try_to_load_stub_cached(
|
||||||
|
evaluator, import_names[:-1], NO_CONTEXTS,
|
||||||
|
parent_module_context=None, sys_path=sys_path)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
# 1. Try to load foo-stubs folders on path for import name foo.
|
# 1. Try to load foo-stubs folders on path for import name foo.
|
||||||
if not parent_module_context:
|
if len(import_names) == 1:
|
||||||
# foo-stubs
|
# foo-stubs
|
||||||
for p in sys_path:
|
for p in sys_path:
|
||||||
init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi'
|
init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi'
|
||||||
|
|||||||
@@ -104,6 +104,9 @@ def test_getitem_on_none(Script):
|
|||||||
assert issue.name == 'type-error-not-subscriptable'
|
assert issue.name == 'type-error-not-subscriptable'
|
||||||
|
|
||||||
|
|
||||||
|
def _return_int():
|
||||||
|
return 1
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'attribute, expected_name, expected_parent', [
|
'attribute, expected_name, expected_parent', [
|
||||||
('x', 'int', 'builtins'),
|
('x', 'int', 'builtins'),
|
||||||
@@ -112,6 +115,7 @@ def test_getitem_on_none(Script):
|
|||||||
('cos', 'cos', 'math'),
|
('cos', 'cos', 'math'),
|
||||||
('dec', 'Decimal', 'decimal'),
|
('dec', 'Decimal', 'decimal'),
|
||||||
('dt', 'datetime', 'datetime'),
|
('dt', 'datetime', 'datetime'),
|
||||||
|
('ret_int', '_return_int', 'test.test_evaluate.test_compiled'),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_parent_context(same_process_evaluator, attribute, expected_name, expected_parent):
|
def test_parent_context(same_process_evaluator, attribute, expected_name, expected_parent):
|
||||||
@@ -126,6 +130,7 @@ def test_parent_context(same_process_evaluator, attribute, expected_name, expect
|
|||||||
cos = math.cos
|
cos = math.cos
|
||||||
dec = decimal.Decimal(1)
|
dec = decimal.Decimal(1)
|
||||||
dt = datetime.datetime(2000, 1, 1)
|
dt = datetime.datetime(2000, 1, 1)
|
||||||
|
ret_int = _return_int
|
||||||
|
|
||||||
o = compiled.CompiledObject(
|
o = compiled.CompiledObject(
|
||||||
same_process_evaluator,
|
same_process_evaluator,
|
||||||
|
|||||||
Reference in New Issue
Block a user