1
0
forked from VimPlug/jedi

change the create_stub_module stuff a bit

This commit is contained in:
Dave Halter
2020-10-24 10:19:20 +02:00
parent 6094e7b39a
commit a03a093e2c
5 changed files with 12 additions and 9 deletions

View File

@@ -196,6 +196,7 @@ class Script:
# We are in a stub file. Try to load the stub properly. # We are in a stub file. Try to load the stub properly.
stub_module = load_proper_stub_module( stub_module = load_proper_stub_module(
self._inference_state, self._inference_state,
self._inference_state.latest_grammar,
file_io, file_io,
names, names,
self._module_node self._module_node

View File

@@ -279,8 +279,8 @@ def _try_to_load_stub_from_file(inference_state, python_value_set, file_io, impo
return None return None
else: else:
return create_stub_module( return create_stub_module(
inference_state, python_value_set, stub_module_node, file_io, inference_state, inference_state.latest_grammar, python_value_set,
import_names stub_module_node, file_io, import_names
) )
@@ -294,7 +294,8 @@ def parse_stub_module(inference_state, file_io):
) )
def create_stub_module(inference_state, python_value_set, stub_module_node, file_io, import_names): def create_stub_module(inference_state, grammar, python_value_set,
stub_module_node, file_io, import_names):
if import_names == ('typing',): if import_names == ('typing',):
module_cls = TypingModuleWrapper module_cls = TypingModuleWrapper
else: else:
@@ -306,7 +307,7 @@ def create_stub_module(inference_state, python_value_set, stub_module_node, file
string_names=import_names, string_names=import_names,
# The code was loaded with latest_grammar, so use # The code was loaded with latest_grammar, so use
# that. # that.
code_lines=get_cached_code_lines(inference_state.latest_grammar, file_io.path), code_lines=get_cached_code_lines(grammar, file_io.path),
is_package=file_name == '__init__.pyi', is_package=file_name == '__init__.pyi',
) )
return stub_module_value return stub_module_value

View File

@@ -3,7 +3,7 @@ from pathlib import Path
from jedi.inference.gradual.typeshed import TYPESHED_PATH, create_stub_module from jedi.inference.gradual.typeshed import TYPESHED_PATH, create_stub_module
def load_proper_stub_module(inference_state, file_io, import_names, module_node): def load_proper_stub_module(inference_state, grammar, file_io, import_names, module_node):
""" """
This function is given a random .pyi file and should return the proper This function is given a random .pyi file and should return the proper
module. module.
@@ -27,7 +27,8 @@ def load_proper_stub_module(inference_state, file_io, import_names, module_node)
actual_value_set = inference_state.import_module(import_names, prefer_stubs=False) actual_value_set = inference_state.import_module(import_names, prefer_stubs=False)
stub = create_stub_module( stub = create_stub_module(
inference_state, actual_value_set, module_node, file_io, import_names inference_state, grammar, actual_value_set,
module_node, file_io, import_names
) )
inference_state.stub_module_cache[import_names] = stub inference_state.stub_module_cache[import_names] = stub
return stub return stub

View File

@@ -498,8 +498,8 @@ def load_module_from_path(inference_state, file_io, import_names=None, is_packag
values = NO_VALUES values = NO_VALUES
return create_stub_module( return create_stub_module(
inference_state, values, parse_stub_module(inference_state, file_io), inference_state, inference_state.latest_grammar, values,
file_io, import_names parse_stub_module(inference_state, file_io), file_io, import_names
) )
else: else:
module = _load_python_module( module = _load_python_module(

View File

@@ -70,7 +70,7 @@ def test_stub_get_line_code(Script):
script = Script(code) script = Script(code)
d, = script.goto(only_stubs=True) d, = script.goto(only_stubs=True)
assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n' assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n'
del parser_cache[script._inference_state.latest_grammar._hashed][str(d.module_path)] del parser_cache[script._inference_state.latest_grammar._hashed][d.module_path]
d, = Script(path=d.module_path).goto(d.line, d.column, only_stubs=True) d, = Script(path=d.module_path).goto(d.line, d.column, only_stubs=True)
assert d.is_stub() assert d.is_stub()
assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n' assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n'