Fix get_line_code for stubs

This commit is contained in:
Dave Halter
2020-10-24 10:12:21 +02:00
parent 98d0a55a02
commit 6094e7b39a
2 changed files with 13 additions and 1 deletions

View File

@@ -160,7 +160,7 @@ class Script:
self._module_node, code = self._inference_state.parse_and_get_code(
code=code,
path=self.path,
use_latest_grammar=path and path.suffix == 'pyi',
use_latest_grammar=path and path.suffix == '.pyi',
cache=False, # No disk cache, because the current script often changes.
diff_cache=settings.fast_parser,
cache_path=settings.cache_directory,

View File

@@ -1,4 +1,5 @@
import os
from parso.cache import parser_cache
from test.helpers import root_dir
from jedi.api.project import Project
@@ -64,6 +65,17 @@ def test_goto_import(Script):
assert not d.is_stub()
def test_stub_get_line_code(Script):
code = 'from abc import ABC; ABC'
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)]
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'
def test_os_stat_result(Script):
d, = Script('import os; os.stat_result').goto()
assert d.is_stub()