1
0
forked from VimPlug/jedi

Make namespace folders work with stubs

This commit is contained in:
Dave Halter
2019-05-15 21:55:54 +02:00
parent b7eeb60e9c
commit e4170d65b7
7 changed files with 37 additions and 8 deletions

View File

@@ -158,6 +158,9 @@ class Context(HelperContextMixin, BaseContext):
def is_module(self):
return False
def is_namespace(self):
return False
def is_compiled(self):
return False

View File

@@ -54,6 +54,9 @@ class ImplicitNamespaceContext(Context, SubModuleDictMixin):
def py__name__(self):
return self._fullname
def is_namespace(self):
return True
def is_stub(self):
return False

View File

@@ -160,12 +160,18 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
pass
else:
file_path = method()
if file_path is not None and file_path.endswith('.py'):
file_paths = []
if c.is_namespace():
file_paths = [os.path.join(p, '__init__.pyi') for p in c.py__path__()]
elif file_path is not None and file_path.endswith('.py'):
file_paths = [file_path + 'i']
for file_path in file_paths:
m = _try_to_load_stub_from_file(
evaluator,
actual_context_set,
# The file path should end with .pyi
file_path + 'i',
file_path,
import_names
)
if m is not None:
@@ -186,14 +192,13 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
else:
check_path = sys_path
names_for_path = import_names
names_for_path = names_for_path[:-1] + (names_for_path[-1] + '.pyi',)
for p in check_path:
m = _try_to_load_stub_from_file(
evaluator,
actual_context_set,
os.path.join(p, *names_for_path),
import_names
os.path.join(p, *names_for_path) + '.pyi',
import_names,
)
if m is not None:
return m