diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index a1c3c5a65..34718881d 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -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 diff --git a/jedi/inference/gradual/typeshed.py b/jedi/inference/gradual/typeshed.py index 6295294d7..a4b287868 100644 --- a/jedi/inference/gradual/typeshed.py +++ b/jedi/inference/gradual/typeshed.py @@ -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 ) @@ -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: @@ -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 diff --git a/jedi/inference/gradual/utils.py b/jedi/inference/gradual/utils.py index 1fc90e7f3..af3703c7a 100644 --- a/jedi/inference/gradual/utils.py +++ b/jedi/inference/gradual/utils.py @@ -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. @@ -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 diff --git a/jedi/inference/imports.py b/jedi/inference/imports.py index 5ae5819fa..f464b08b8 100644 --- a/jedi/inference/imports.py +++ b/jedi/inference/imports.py @@ -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( diff --git a/test/test_inference/test_gradual/test_conversion.py b/test/test_inference/test_gradual/test_conversion.py index 809f87ae4..c77a06b03 100644 --- a/test/test_inference/test_gradual/test_conversion.py +++ b/test/test_inference/test_gradual/test_conversion.py @@ -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'