mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Make namespace folders work with stubs
This commit is contained in:
@@ -158,6 +158,9 @@ class Context(HelperContextMixin, BaseContext):
|
|||||||
def is_module(self):
|
def is_module(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_namespace(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def is_compiled(self):
|
def is_compiled(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ class ImplicitNamespaceContext(Context, SubModuleDictMixin):
|
|||||||
def py__name__(self):
|
def py__name__(self):
|
||||||
return self._fullname
|
return self._fullname
|
||||||
|
|
||||||
|
def is_namespace(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def is_stub(self):
|
def is_stub(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -160,12 +160,18 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
file_path = method()
|
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(
|
m = _try_to_load_stub_from_file(
|
||||||
evaluator,
|
evaluator,
|
||||||
actual_context_set,
|
actual_context_set,
|
||||||
# The file path should end with .pyi
|
# The file path should end with .pyi
|
||||||
file_path + 'i',
|
file_path,
|
||||||
import_names
|
import_names
|
||||||
)
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
@@ -186,14 +192,13 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
else:
|
else:
|
||||||
check_path = sys_path
|
check_path = sys_path
|
||||||
names_for_path = import_names
|
names_for_path = import_names
|
||||||
names_for_path = names_for_path[:-1] + (names_for_path[-1] + '.pyi',)
|
|
||||||
|
|
||||||
for p in check_path:
|
for p in check_path:
|
||||||
m = _try_to_load_stub_from_file(
|
m = _try_to_load_stub_from_file(
|
||||||
evaluator,
|
evaluator,
|
||||||
actual_context_set,
|
actual_context_set,
|
||||||
os.path.join(p, *names_for_path),
|
os.path.join(p, *names_for_path) + '.pyi',
|
||||||
import_names
|
import_names,
|
||||||
)
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
return m
|
return m
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
in_stub_only_folder: int
|
||||||
2
test/completion/stub_folder/with_stub_folder/__init__.py
Normal file
2
test/completion/stub_folder/with_stub_folder/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
in_with_stub_both_folder = 5
|
||||||
|
in_with_stub_python_folder = 8
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
in_with_stub_both_folder: str
|
||||||
|
in_with_stub_stub_folder: float
|
||||||
@@ -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()
|
#? int()
|
||||||
stub_only.in_stub_only
|
stub_only.in_stub_only
|
||||||
|
|
||||||
#? str()
|
#? str()
|
||||||
with_stub.in_with_stub_both
|
with_stub.in_with_stub_both
|
||||||
#? int()
|
#?
|
||||||
with_stub.in_with_stub_python
|
with_stub.in_with_stub_python
|
||||||
#? float()
|
#? float()
|
||||||
with_stub.in_with_stub_stub
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user