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

View File

@@ -0,0 +1 @@
in_stub_only_folder: int

View File

@@ -0,0 +1,2 @@
in_with_stub_both_folder = 5
in_with_stub_python_folder = 8

View File

@@ -0,0 +1,2 @@
in_with_stub_both_folder: str
in_with_stub_stub_folder: float

View File

@@ -1,11 +1,24 @@
from stub_folder import with_stub, stub_only
from stub_folder import with_stub, stub_only, with_stub_folder, stub_only_folder
# Just files
#? int()
stub_only.in_stub_only
#? str()
with_stub.in_with_stub_both
#? int()
#?
with_stub.in_with_stub_python
#? float()
with_stub.in_with_stub_stub
# Folders
#? int()
stub_only_folder.in_stub_only_folder
#? str()
with_stub_folder.in_with_stub_both_folder
#?
with_stub_folder.in_with_stub_python_folder
#? float()
with_stub_folder.in_with_stub_stub_folder