Skip to content

Commit

Permalink
change the create_stub_module stuff a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Oct 24, 2020
1 parent 6094e7b commit a03a093
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions jedi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def _get_module(self):
# We are in a stub file. Try to load the stub properly.
stub_module = load_proper_stub_module(
self._inference_state,
self._inference_state.latest_grammar,
file_io,
names,
self._module_node
Expand Down
9 changes: 5 additions & 4 deletions jedi/inference/gradual/typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def _try_to_load_stub_from_file(inference_state, python_value_set, file_io, impo
return None
else:
return create_stub_module(
inference_state, python_value_set, stub_module_node, file_io,
import_names
inference_state, inference_state.latest_grammar, python_value_set,
stub_module_node, file_io, import_names
)


Expand All @@ -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',):
module_cls = TypingModuleWrapper
else:
Expand All @@ -306,7 +307,7 @@ def create_stub_module(inference_state, python_value_set, stub_module_node, file
string_names=import_names,
# The code was loaded with latest_grammar, so use
# 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',
)
return stub_module_value
5 changes: 3 additions & 2 deletions jedi/inference/gradual/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
module.
Expand All @@ -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)

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
return stub
Expand Down
4 changes: 2 additions & 2 deletions jedi/inference/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ def load_module_from_path(inference_state, file_io, import_names=None, is_packag
values = NO_VALUES

return create_stub_module(
inference_state, values, parse_stub_module(inference_state, file_io),
file_io, import_names
inference_state, inference_state.latest_grammar, values,
parse_stub_module(inference_state, file_io), file_io, import_names
)
else:
module = _load_python_module(
Expand Down
2 changes: 1 addition & 1 deletion test/test_inference/test_gradual/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_stub_get_line_code(Script):
script = Script(code)
d, = script.goto(only_stubs=True)
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)
assert d.is_stub()
assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n'
Expand Down

0 comments on commit a03a093

Please sign in to comment.