mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix get_line_code for stubs
This commit is contained in:
@@ -160,7 +160,7 @@ class Script:
|
|||||||
self._module_node, code = self._inference_state.parse_and_get_code(
|
self._module_node, code = self._inference_state.parse_and_get_code(
|
||||||
code=code,
|
code=code,
|
||||||
path=self.path,
|
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.
|
cache=False, # No disk cache, because the current script often changes.
|
||||||
diff_cache=settings.fast_parser,
|
diff_cache=settings.fast_parser,
|
||||||
cache_path=settings.cache_directory,
|
cache_path=settings.cache_directory,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from parso.cache import parser_cache
|
||||||
|
|
||||||
from test.helpers import root_dir
|
from test.helpers import root_dir
|
||||||
from jedi.api.project import Project
|
from jedi.api.project import Project
|
||||||
@@ -64,6 +65,17 @@ def test_goto_import(Script):
|
|||||||
assert not d.is_stub()
|
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):
|
def test_os_stat_result(Script):
|
||||||
d, = Script('import os; os.stat_result').goto()
|
d, = Script('import os; os.stat_result').goto()
|
||||||
assert d.is_stub()
|
assert d.is_stub()
|
||||||
|
|||||||
Reference in New Issue
Block a user