forked from VimPlug/jedi
Don't use goto_definitions anymore, use infer
This commit is contained in:
@@ -7,18 +7,18 @@ from jedi.inference.gradual.conversion import convert_names
|
||||
|
||||
def test_sqlite3_conversion(Script):
|
||||
script1 = Script('import sqlite3; sqlite3.Connection')
|
||||
d, = script1.goto_definitions()
|
||||
d, = script1.infer()
|
||||
|
||||
assert not d.module_path
|
||||
assert d.full_name == 'sqlite3.Connection'
|
||||
assert convert_names([d._name], only_stubs=True)
|
||||
|
||||
d, = script1.goto_definitions(only_stubs=True)
|
||||
d, = script1.infer(only_stubs=True)
|
||||
assert d.is_stub()
|
||||
assert d.full_name == 'sqlite3.dbapi2.Connection'
|
||||
|
||||
script2 = Script(path=d.module_path, line=d.line, column=d.column)
|
||||
d, = script2.goto_definitions()
|
||||
script2 = Script(path=d.module_path)
|
||||
d, = script2.infer(line=d.line, column=d.column)
|
||||
assert not d.is_stub()
|
||||
assert d.full_name == 'sqlite3.Connection'
|
||||
v, = d._name.infer()
|
||||
|
||||
@@ -23,5 +23,5 @@ def ScriptInStubFolder(Script):
|
||||
]
|
||||
)
|
||||
def test_find_stubs_infer(ScriptInStubFolder, code, expected):
|
||||
defs = ScriptInStubFolder(code).goto_definitions()
|
||||
defs = ScriptInStubFolder(code).infer()
|
||||
assert [d.name for d in defs] == expected
|
||||
|
||||
@@ -66,7 +66,7 @@ def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way,
|
||||
if type_ == 'goto':
|
||||
defs = s.goto_assignments(follow_imports=True, **kwargs)
|
||||
else:
|
||||
defs = s.goto_definitions(**kwargs)
|
||||
defs = s.infer(**kwargs)
|
||||
else:
|
||||
goto_defs = s.goto_assignments(
|
||||
# Prefering stubs when we want to go to python and vice versa
|
||||
|
||||
@@ -46,21 +46,21 @@ def test_get_stub_files():
|
||||
|
||||
def test_function(Script, environment):
|
||||
code = 'import threading; threading.current_thread'
|
||||
def_, = Script(code).goto_definitions()
|
||||
def_, = Script(code).infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, FunctionValue), value
|
||||
|
||||
def_, = Script(code + '()').goto_definitions()
|
||||
def_, = Script(code + '()').infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, TreeInstance)
|
||||
|
||||
def_, = Script('import threading; threading.Thread').goto_definitions()
|
||||
def_, = Script('import threading; threading.Thread').infer()
|
||||
assert isinstance(def_._name._value, ClassValue), def_
|
||||
|
||||
|
||||
def test_keywords_variable(Script):
|
||||
code = 'import keyword; keyword.kwlist'
|
||||
for seq in Script(code).goto_definitions():
|
||||
for seq in Script(code).infer():
|
||||
assert seq.name == 'Sequence'
|
||||
# This points towards the typeshed implementation
|
||||
stub_seq, = seq.goto(only_stubs=True)
|
||||
@@ -68,31 +68,31 @@ def test_keywords_variable(Script):
|
||||
|
||||
|
||||
def test_class(Script):
|
||||
def_, = Script('import threading; threading.Thread').goto_definitions()
|
||||
def_, = Script('import threading; threading.Thread').infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, ClassValue), value
|
||||
|
||||
|
||||
def test_instance(Script):
|
||||
def_, = Script('import threading; threading.Thread()').goto_definitions()
|
||||
def_, = Script('import threading; threading.Thread()').infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, TreeInstance)
|
||||
|
||||
|
||||
def test_class_function(Script):
|
||||
def_, = Script('import threading; threading.Thread.getName').goto_definitions()
|
||||
def_, = Script('import threading; threading.Thread.getName').infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, MethodValue), value
|
||||
|
||||
|
||||
def test_method(Script):
|
||||
code = 'import threading; threading.Thread().getName'
|
||||
def_, = Script(code).goto_definitions()
|
||||
def_, = Script(code).infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, BoundMethod), value
|
||||
assert isinstance(value._wrapped_value, MethodValue), value
|
||||
|
||||
def_, = Script(code + '()').goto_definitions()
|
||||
def_, = Script(code + '()').infer()
|
||||
value = def_._name._value
|
||||
assert isinstance(value, TreeInstance)
|
||||
assert value.class_value.py__name__() == 'str'
|
||||
@@ -100,13 +100,13 @@ def test_method(Script):
|
||||
|
||||
def test_sys_exc_info(Script):
|
||||
code = 'import sys; sys.exc_info()'
|
||||
none, def_ = Script(code + '[1]').goto_definitions()
|
||||
none, def_ = Script(code + '[1]').infer()
|
||||
# It's an optional.
|
||||
assert def_.name == 'BaseException'
|
||||
assert def_.type == 'instance'
|
||||
assert none.name == 'NoneType'
|
||||
|
||||
none, def_ = Script(code + '[0]').goto_definitions()
|
||||
none, def_ = Script(code + '[0]').infer()
|
||||
assert def_.name == 'BaseException'
|
||||
assert def_.type == 'class'
|
||||
|
||||
@@ -114,7 +114,7 @@ def test_sys_exc_info(Script):
|
||||
def test_sys_getwindowsversion(Script, environment):
|
||||
# This should only exist on Windows, but type inference should happen
|
||||
# everywhere.
|
||||
definitions = Script('import sys; sys.getwindowsversion().major').goto_definitions()
|
||||
definitions = Script('import sys; sys.getwindowsversion().major').infer()
|
||||
if environment.version_info.major == 2:
|
||||
assert not definitions
|
||||
else:
|
||||
@@ -127,19 +127,19 @@ def test_sys_hexversion(Script):
|
||||
def_, = script.complete()
|
||||
assert isinstance(def_._name, stub_value._StubName), def_._name
|
||||
assert typeshed.TYPESHED_PATH in def_.module_path
|
||||
def_, = script.goto_definitions()
|
||||
def_, = script.infer()
|
||||
assert def_.name == 'int'
|
||||
|
||||
|
||||
def test_math(Script):
|
||||
def_, = Script('import math; math.acos()').goto_definitions()
|
||||
def_, = Script('import math; math.acos()').infer()
|
||||
assert def_.name == 'float'
|
||||
value = def_._name._value
|
||||
assert value
|
||||
|
||||
|
||||
def test_type_var(Script):
|
||||
def_, = Script('import typing; T = typing.TypeVar("T1")').goto_definitions()
|
||||
def_, = Script('import typing; T = typing.TypeVar("T1")').infer()
|
||||
assert def_.name == 'TypeVar'
|
||||
assert def_.description == 'TypeVar = object()'
|
||||
|
||||
@@ -152,7 +152,7 @@ def test_type_var(Script):
|
||||
)
|
||||
def test_math_is_stub(Script, code, full_name):
|
||||
s = Script(code)
|
||||
cos, = s.goto_definitions()
|
||||
cos, = s.infer()
|
||||
wanted = os.path.join('typeshed', 'stdlib', '2and3', 'math.pyi')
|
||||
assert cos.module_path.endswith(wanted)
|
||||
assert cos.is_stub() is True
|
||||
@@ -168,7 +168,7 @@ def test_math_is_stub(Script, code, full_name):
|
||||
|
||||
def test_goto_stubs(Script):
|
||||
s = Script('import os; os')
|
||||
os_module, = s.goto_definitions()
|
||||
os_module, = s.infer()
|
||||
assert os_module.full_name == 'os'
|
||||
assert os_module.is_stub() is False
|
||||
stub, = os_module.goto(only_stubs=True)
|
||||
@@ -199,20 +199,16 @@ def test_goto_stubs_on_itself(Script, code, type_):
|
||||
"""
|
||||
s = Script(code)
|
||||
if type_ == 'infer':
|
||||
def_, = s.goto_definitions()
|
||||
def_, = s.infer()
|
||||
else:
|
||||
def_, = s.goto_assignments(follow_imports=True)
|
||||
stub, = def_.goto(only_stubs=True)
|
||||
|
||||
script_on_source = Script(
|
||||
path=def_.module_path,
|
||||
line=def_.line,
|
||||
column=def_.column
|
||||
)
|
||||
script_on_source = Script(path=def_.module_path)
|
||||
if type_ == 'infer':
|
||||
definition, = script_on_source.goto_definitions()
|
||||
definition, = script_on_source.infer(def_.line, def_.column)
|
||||
else:
|
||||
definition, = script_on_source.goto_assignments()
|
||||
definition, = script_on_source.goto(def_.line, def_.column)
|
||||
same_stub, = definition.goto(only_stubs=True)
|
||||
_assert_is_same(same_stub, stub)
|
||||
_assert_is_same(definition, def_)
|
||||
@@ -221,15 +217,13 @@ def test_goto_stubs_on_itself(Script, code, type_):
|
||||
# And the reverse.
|
||||
script_on_stub = Script(
|
||||
path=same_stub.module_path,
|
||||
line=same_stub.line,
|
||||
column=same_stub.column
|
||||
)
|
||||
|
||||
if type_ == 'infer':
|
||||
same_definition, = script_on_stub.goto_definitions()
|
||||
same_definition, = script_on_stub.infer(same_stub.line, same_stub.column)
|
||||
same_definition2, = same_stub.infer()
|
||||
else:
|
||||
same_definition, = script_on_stub.goto_assignments()
|
||||
same_definition, = script_on_stub.goto(same_stub.line, same_stub.column)
|
||||
same_definition2, = same_stub.goto()
|
||||
|
||||
_assert_is_same(same_definition, definition)
|
||||
|
||||
Reference in New Issue
Block a user