Skip to content

Commit

Permalink
Fix get_line_code for stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Oct 24, 2020
1 parent 98d0a55 commit 6094e7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jedi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, code=None, line=None, column=None, path=None,
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,
Expand Down
12 changes: 12 additions & 0 deletions test/test_inference/test_gradual/test_conversion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from parso.cache import parser_cache

from test.helpers import root_dir
from jedi.api.project import Project
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6094e7b

Please sign in to comment.