diff --git a/jedi/evaluate/compiled/mixed.py b/jedi/evaluate/compiled/mixed.py index 50655997..da801c32 100644 --- a/jedi/evaluate/compiled/mixed.py +++ b/jedi/evaluate/compiled/mixed.py @@ -47,9 +47,7 @@ class MixedObject(ContextWrapper): yield MixedObjectFilter(self.evaluator, self) def py__call__(self, arguments): - print(self._wrapped_context) - print(to_stub(self._wrapped_context)) - return self._wrapped_context.py__call__(arguments) + return (to_stub(self._wrapped_context) or self._wrapped_context).py__call__(arguments) def __repr__(self): return '<%s: %s>' % ( diff --git a/jedi/evaluate/gradual/typeshed.py b/jedi/evaluate/gradual/typeshed.py index 4019e149..10424f2f 100644 --- a/jedi/evaluate/gradual/typeshed.py +++ b/jedi/evaluate/gradual/typeshed.py @@ -4,7 +4,7 @@ import re from jedi.file_io import FileIO from jedi._compatibility import FileNotFoundError, cast_path 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 _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: 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] = result = \ _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 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. - if not parent_module_context: + if len(import_names) == 1: # foo-stubs for p in sys_path: init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi' diff --git a/test/test_evaluate/test_compiled.py b/test/test_evaluate/test_compiled.py index 1c6f5190..a04dfd4b 100644 --- a/test/test_evaluate/test_compiled.py +++ b/test/test_evaluate/test_compiled.py @@ -104,6 +104,9 @@ def test_getitem_on_none(Script): assert issue.name == 'type-error-not-subscriptable' +def _return_int(): + return 1 + @pytest.mark.parametrize( 'attribute, expected_name, expected_parent', [ ('x', 'int', 'builtins'), @@ -112,6 +115,7 @@ def test_getitem_on_none(Script): ('cos', 'cos', 'math'), ('dec', 'Decimal', 'decimal'), ('dt', 'datetime', 'datetime'), + ('ret_int', '_return_int', 'test.test_evaluate.test_compiled'), ] ) 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 dec = decimal.Decimal(1) dt = datetime.datetime(2000, 1, 1) + ret_int = _return_int o = compiled.CompiledObject( same_process_evaluator,