forked from VimPlug/jedi
Don't use goto_definitions anymore, use infer
This commit is contained in:
@@ -130,12 +130,12 @@ def test_goto_assignments_on_non_name(Script, environment):
|
||||
assert Script('True').goto_assignments() == []
|
||||
|
||||
|
||||
def test_goto_definitions_on_non_name(Script):
|
||||
assert Script('import x', column=0).goto_definitions() == []
|
||||
def test_infer_on_non_name(Script):
|
||||
assert Script('import x').infer(column=0) == []
|
||||
|
||||
|
||||
def test_goto_definitions_on_generator(Script):
|
||||
def_, = Script('def x(): yield 1\ny=x()\ny').goto_definitions()
|
||||
def test_infer_on_generator(Script):
|
||||
def_, = Script('def x(): yield 1\ny=x()\ny').infer()
|
||||
assert def_.name == 'Generator'
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ def test_goto_definition_not_multiple(Script):
|
||||
else:
|
||||
a = A(1)
|
||||
a''')
|
||||
assert len(Script(s).goto_definitions()) == 1
|
||||
assert len(Script(s).infer()) == 1
|
||||
|
||||
|
||||
def test_usage_description(Script):
|
||||
@@ -264,7 +264,7 @@ def test_goto_definition_cursor(Script):
|
||||
should2 = 8, 10
|
||||
|
||||
def get_def(pos):
|
||||
return [d.description for d in Script(s, *pos).goto_definitions()]
|
||||
return [d.description for d in Script(s).infer(*pos)]
|
||||
|
||||
in_name = get_def(in_name)
|
||||
under_score = get_def(under_score)
|
||||
@@ -290,7 +290,7 @@ def test_no_statement_parent(Script):
|
||||
pass
|
||||
|
||||
variable = f if random.choice([0, 1]) else C""")
|
||||
defs = Script(source, column=3).goto_definitions()
|
||||
defs = Script(source).infer(column=3)
|
||||
defs = sorted(defs, key=lambda d: d.line)
|
||||
assert [d.description for d in defs] == ['def f', 'class C']
|
||||
|
||||
@@ -303,7 +303,7 @@ def test_backslash_continuation_and_bracket(Script):
|
||||
|
||||
lines = code.splitlines()
|
||||
column = lines[-1].index('(')
|
||||
def_, = Script(code, line=len(lines), column=column).goto_definitions()
|
||||
def_, = Script(code).infer(line=len(lines), column=column)
|
||||
assert def_.name == 'int'
|
||||
|
||||
|
||||
@@ -355,6 +355,6 @@ def test_file_fuzzy_completion(Script):
|
||||
]
|
||||
)
|
||||
def test_goto_on_string(Script, code, column):
|
||||
script = Script(code, column=column)
|
||||
assert not script.goto_definitions()
|
||||
assert not script.goto_assignments()
|
||||
script = Script(code)
|
||||
assert not script.infer(column=column)
|
||||
assert not script.goto(column=column)
|
||||
|
||||
@@ -309,7 +309,7 @@ def test_signature_is_definition(Script):
|
||||
"""
|
||||
s = """class Spam(): pass\nSpam"""
|
||||
signature = Script(s + '(').call_signatures()[0]
|
||||
definition = Script(s + '(', column=0).goto_definitions()[0]
|
||||
definition = Script(s + '(').infer(column=0)[0]
|
||||
signature.line == 1
|
||||
signature.column == 6
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ from ..helpers import get_example_dir
|
||||
|
||||
|
||||
def test_is_keyword(Script):
|
||||
results = Script('str', 1, 1, None).goto_definitions()
|
||||
results = Script('str', path=None).infer(1, 1)
|
||||
assert len(results) == 1 and results[0].is_keyword is False
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ def test_basedefinition_type(Script, names):
|
||||
source += dedent("""
|
||||
variable = sys or C or x or f or g or g() or h""")
|
||||
lines = source.splitlines()
|
||||
script = Script(source, len(lines), len('variable'), None)
|
||||
definitions += script.goto_definitions()
|
||||
script = Script(source, path=None)
|
||||
definitions += script.infer(len(lines), len('variable'))
|
||||
|
||||
script2 = Script(source, 4, len('class C'), None)
|
||||
definitions += script2.usages()
|
||||
@@ -96,7 +96,7 @@ def test_function_call_signature_in_doc(Script):
|
||||
defs = Script("""
|
||||
def f(x, y=1, z='a'):
|
||||
pass
|
||||
f""").goto_definitions()
|
||||
f""").infer()
|
||||
doc = defs[0].docstring()
|
||||
assert "f(x, y=1, z='a')" in str(doc)
|
||||
|
||||
@@ -112,7 +112,7 @@ def test_class_call_signature(Script):
|
||||
class Foo:
|
||||
def __init__(self, x, y=1, z='a'):
|
||||
pass
|
||||
Foo""").goto_definitions()
|
||||
Foo""").infer()
|
||||
doc = defs[0].docstring()
|
||||
assert doc == "Foo(x, y=1, z='a')"
|
||||
|
||||
@@ -204,7 +204,7 @@ def test_signature_params(Script):
|
||||
pass
|
||||
foo''')
|
||||
|
||||
check(Script(s).goto_definitions())
|
||||
check(Script(s).infer())
|
||||
|
||||
check(Script(s).goto_assignments())
|
||||
check(Script(s + '\nbar=foo\nbar').goto_assignments())
|
||||
@@ -451,7 +451,7 @@ def test_builtin_module_with_path(Script):
|
||||
a path or not. It shouldn't have a module_path, because that is just
|
||||
confusing.
|
||||
"""
|
||||
semlock, = Script('from _multiprocessing import SemLock').goto_definitions()
|
||||
semlock, = Script('from _multiprocessing import SemLock').infer()
|
||||
assert isinstance(semlock._name, CompiledValueName)
|
||||
assert semlock.module_path is None
|
||||
assert semlock.in_builtin_module() is True
|
||||
@@ -491,7 +491,7 @@ def test_inheritance_module_path(Script, goto_assignment, code, name, file_name)
|
||||
|
||||
script = Script(code, path=whatever_path)
|
||||
if goto_assignment is None:
|
||||
func, = script.goto_definitions()
|
||||
func, = script.infer()
|
||||
else:
|
||||
func, = script.goto_assignments(follow_imports=goto_assignment)
|
||||
assert func.type == 'function'
|
||||
|
||||
@@ -66,13 +66,13 @@ def test_error_in_environment(inference_state, Script, environment):
|
||||
with pytest.raises(jedi.InternalError):
|
||||
inference_state.compiled_subprocess._test_raise_error(KeyboardInterrupt)
|
||||
# Jedi should still work.
|
||||
def_, = Script('str').goto_definitions()
|
||||
def_, = Script('str').infer()
|
||||
assert def_.name == 'str'
|
||||
|
||||
|
||||
def test_stdout_in_subprocess(inference_state, Script):
|
||||
inference_state.compiled_subprocess._test_print(stdout='.')
|
||||
Script('1').goto_definitions()
|
||||
Script('1').infer()
|
||||
|
||||
|
||||
def test_killed_subprocess(inference_state, Script, environment):
|
||||
@@ -83,9 +83,9 @@ def test_killed_subprocess(inference_state, Script, environment):
|
||||
# Since the process was terminated (and nobody knows about it) the first
|
||||
# Jedi call fails.
|
||||
with pytest.raises(jedi.InternalError):
|
||||
Script('str').goto_definitions()
|
||||
Script('str').infer()
|
||||
|
||||
def_, = Script('str').goto_definitions()
|
||||
def_, = Script('str').infer()
|
||||
# Jedi should now work again.
|
||||
assert def_.name == 'str'
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class MixinTestFullName(object):
|
||||
|
||||
|
||||
class TestFullNameWithGotoDefinitions(MixinTestFullName, TestCase):
|
||||
operation = 'goto_definitions'
|
||||
operation = 'infer'
|
||||
|
||||
def test_tuple_mapping(self):
|
||||
if self.environment.version_info.major == 2:
|
||||
@@ -97,9 +97,9 @@ def test_sub_module(Script, jedi_path):
|
||||
path.
|
||||
"""
|
||||
sys_path = [jedi_path]
|
||||
defs = Script('from jedi.api import classes; classes', sys_path=sys_path).goto_definitions()
|
||||
defs = Script('from jedi.api import classes; classes', sys_path=sys_path).infer()
|
||||
assert [d.full_name for d in defs] == ['jedi.api.classes']
|
||||
defs = Script('import jedi.api; jedi.api', sys_path=sys_path).goto_definitions()
|
||||
defs = Script('import jedi.api; jedi.api', sys_path=sys_path).infer()
|
||||
assert [d.full_name for d in defs] == ['jedi.api']
|
||||
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ def test_property_content():
|
||||
return 1
|
||||
|
||||
foo = Foo3()
|
||||
def_, = jedi.Interpreter('foo.bar', [locals()]).goto_definitions()
|
||||
def_, = jedi.Interpreter('foo.bar', [locals()]).infer()
|
||||
assert def_.name == 'int'
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ def test_completion_param_annotations():
|
||||
assert [d.name for d in b.infer()] == ['str']
|
||||
assert {d.name for d in c.infer()} == {'int', 'float'}
|
||||
|
||||
d, = jedi.Interpreter('foo()', [locals()]).goto_definitions()
|
||||
d, = jedi.Interpreter('foo()', [locals()]).infer()
|
||||
assert d.name == 'bytes'
|
||||
|
||||
|
||||
@@ -397,7 +397,7 @@ def test_repr_execution_issue():
|
||||
er = ErrorRepr()
|
||||
|
||||
script = jedi.Interpreter('er', [locals()])
|
||||
d, = script.goto_definitions()
|
||||
d, = script.infer()
|
||||
assert d.name == 'ErrorRepr'
|
||||
assert d.type == 'instance'
|
||||
|
||||
@@ -452,7 +452,7 @@ def test_name_not_findable():
|
||||
|
||||
def test_stubs_working():
|
||||
from multiprocessing import cpu_count
|
||||
defs = jedi.Interpreter("cpu_count()", [locals()]).goto_definitions()
|
||||
defs = jedi.Interpreter("cpu_count()", [locals()]).infer()
|
||||
assert [d.name for d in defs] == ['int']
|
||||
|
||||
|
||||
@@ -559,7 +559,7 @@ def test_type_var():
|
||||
"""This was an issue before, see Github #1369"""
|
||||
import typing
|
||||
x = typing.TypeVar('myvar')
|
||||
def_, = jedi.Interpreter('x', [locals()]).goto_definitions()
|
||||
def_, = jedi.Interpreter('x', [locals()]).infer()
|
||||
assert def_.name == 'TypeVar'
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_goto_assignments_keyword(Script):
|
||||
|
||||
def test_keyword(Script, environment):
|
||||
""" github jedi-vim issue #44 """
|
||||
defs = Script("print").goto_definitions()
|
||||
defs = Script("print").infer()
|
||||
if environment.version_info.major < 3:
|
||||
assert defs == []
|
||||
else:
|
||||
@@ -26,7 +26,7 @@ def test_keyword(Script, environment):
|
||||
|
||||
completions = Script("import").complete(1, 1)
|
||||
assert len(completions) > 10 and 'if' in [c.name for c in completions]
|
||||
assert Script("assert").goto_definitions() == []
|
||||
assert Script("assert").infer() == []
|
||||
|
||||
|
||||
def test_keyword_attributes(Script):
|
||||
|
||||
@@ -18,7 +18,7 @@ def test_add_dynamic_mods(Script):
|
||||
src2 = 'from .. import setup; setup.r(1)'
|
||||
script = Script(src1, path='../setup.py')
|
||||
imports.load_module(script._inference_state, os.path.abspath(fname), src2)
|
||||
result = script.goto_definitions()
|
||||
result = script.infer()
|
||||
assert len(result) == 1
|
||||
assert result[0].description == 'class int'
|
||||
|
||||
|
||||
@@ -49,11 +49,11 @@ def test_multibyte_script(Script):
|
||||
|
||||
def test_goto_definition_at_zero(Script):
|
||||
"""At zero usually sometimes raises unicode issues."""
|
||||
assert Script("a", 1, 1).goto_definitions() == []
|
||||
s = Script("str", 1, 1).goto_definitions()
|
||||
assert Script("a").infer(1, 1) == []
|
||||
s = Script("str").infer(1, 1)
|
||||
assert len(s) == 1
|
||||
assert list(s)[0].description == 'class str'
|
||||
assert Script("", 1, 0).goto_definitions() == []
|
||||
assert Script("").infer(1, 0) == []
|
||||
|
||||
|
||||
def test_complete_at_zero(Script):
|
||||
|
||||
Reference in New Issue
Block a user