Make sure goto_assignments is no longer used on Definition

This commit is contained in:
Dave Halter
2019-12-20 14:43:20 +01:00
parent 1f4be4bc51
commit 39605bfa08
6 changed files with 24 additions and 24 deletions

View File

@@ -216,7 +216,7 @@ def test_goto_assignments_follow_imports(Script):
definition, = script.goto_assignments(follow_imports=True) definition, = script.goto_assignments(follow_imports=True)
assert (definition.line, definition.column) == start_pos assert (definition.line, definition.column) == start_pos
assert definition.name == 'p' assert definition.name == 'p'
result, = definition.goto_assignments() result, = definition.goto()
assert result.name == 'p' assert result.name == 'p'
result, = definition.infer() result, = definition.infer()
assert result.name == 'int' assert result.name == 'int'

View File

@@ -340,7 +340,7 @@ def test_goto_assignment_repetition(names):
# definition. # definition.
for _ in range(3): for _ in range(3):
assert len(defs) == 1 assert len(defs) == 1
ass = defs[0].goto_assignments() ass = defs[0].goto()
assert ass[0].description == 'a = 1' assert ass[0].description == 'a = 1'
@@ -351,7 +351,7 @@ def test_goto_assignments_named_params(names):
foo(bar=1) foo(bar=1)
""" """
bar = names(dedent(src), references=True)[-1] bar = names(dedent(src), references=True)[-1]
param = bar.goto_assignments()[0] param = bar.goto()[0]
assert (param.line, param.column) == (1, 13) assert (param.line, param.column) == (1, 13)
assert param.type == 'param' assert param.type == 'param'
@@ -360,46 +360,46 @@ def test_class_call(names):
src = 'from threading import Thread; Thread(group=1)' src = 'from threading import Thread; Thread(group=1)'
n = names(src, references=True)[-1] n = names(src, references=True)[-1]
assert n.name == 'group' assert n.name == 'group'
param_def = n.goto_assignments()[0] param_def = n.goto()[0]
assert param_def.name == 'group' assert param_def.name == 'group'
assert param_def.type == 'param' assert param_def.type == 'param'
def test_parentheses(names): def test_parentheses(names):
n = names('("").upper', references=True)[-1] n = names('("").upper', references=True)[-1]
assert n.goto_assignments()[0].name == 'upper' assert n.goto()[0].name == 'upper'
def test_import(names): def test_import(names):
nms = names('from json import load', references=True) nms = names('from json import load', references=True)
assert nms[0].name == 'json' assert nms[0].name == 'json'
assert nms[0].type == 'module' assert nms[0].type == 'module'
n = nms[0].goto_assignments()[0] n = nms[0].goto()[0]
assert n.name == 'json' assert n.name == 'json'
assert n.type == 'module' assert n.type == 'module'
assert nms[1].name == 'load' assert nms[1].name == 'load'
assert nms[1].type == 'function' assert nms[1].type == 'function'
n = nms[1].goto_assignments()[0] n = nms[1].goto()[0]
assert n.name == 'load' assert n.name == 'load'
assert n.type == 'function' assert n.type == 'function'
nms = names('import os; os.path', references=True) nms = names('import os; os.path', references=True)
assert nms[0].name == 'os' assert nms[0].name == 'os'
assert nms[0].type == 'module' assert nms[0].type == 'module'
n = nms[0].goto_assignments()[0] n = nms[0].goto()[0]
assert n.name == 'os' assert n.name == 'os'
assert n.type == 'module' assert n.type == 'module'
n = nms[2].goto_assignments()[0] n = nms[2].goto()[0]
assert n.name == 'path' assert n.name == 'path'
assert n.type == 'module' assert n.type == 'module'
nms = names('import os.path', references=True) nms = names('import os.path', references=True)
n = nms[0].goto_assignments()[0] n = nms[0].goto()[0]
assert n.name == 'os' assert n.name == 'os'
assert n.type == 'module' assert n.type == 'module'
n = nms[1].goto_assignments()[0] n = nms[1].goto()[0]
# This is very special, normally the name doesn't chance, but since # This is very special, normally the name doesn't chance, but since
# os.path is a sys.modules hack, it does. # os.path is a sys.modules hack, it does.
assert n.name in ('macpath', 'ntpath', 'posixpath', 'os2emxpath') assert n.name in ('macpath', 'ntpath', 'posixpath', 'os2emxpath')
@@ -411,7 +411,7 @@ def test_import_alias(names):
assert nms[0].name == 'json' assert nms[0].name == 'json'
assert nms[0].type == 'module' assert nms[0].type == 'module'
assert nms[0]._name.tree_name.parent.type == 'dotted_as_name' assert nms[0]._name.tree_name.parent.type == 'dotted_as_name'
n = nms[0].goto_assignments()[0] n = nms[0].goto()[0]
assert n.name == 'json' assert n.name == 'json'
assert n.type == 'module' assert n.type == 'module'
assert n._name._value.tree_node.type == 'file_input' assert n._name._value.tree_node.type == 'file_input'
@@ -419,7 +419,7 @@ def test_import_alias(names):
assert nms[1].name == 'foo' assert nms[1].name == 'foo'
assert nms[1].type == 'module' assert nms[1].type == 'module'
assert nms[1]._name.tree_name.parent.type == 'dotted_as_name' assert nms[1]._name.tree_name.parent.type == 'dotted_as_name'
ass = nms[1].goto_assignments() ass = nms[1].goto()
assert len(ass) == 1 assert len(ass) == 1
assert ass[0].name == 'json' assert ass[0].name == 'json'
assert ass[0].type == 'module' assert ass[0].type == 'module'

View File

@@ -166,4 +166,4 @@ def test_no_error(names):
assert a.name == 'a' assert a.name == 'a'
assert b.name == 'b' assert b.name == 'b'
assert a20.name == 'a' assert a20.name == 'a'
assert a20.goto_assignments() == [a20] assert a20.goto() == [a20]

View File

@@ -35,8 +35,8 @@ def test_keyword_attributes(Script):
assert def_.complete == '' assert def_.complete == ''
assert def_.is_keyword is True assert def_.is_keyword is True
assert def_.is_stub() is False assert def_.is_stub() is False
assert def_.goto_assignments(only_stubs=True) == [] assert def_.goto(only_stubs=True) == []
assert def_.goto_assignments() == [] assert def_.goto() == []
assert def_.infer() == [] assert def_.infer() == []
assert def_.parent() is None assert def_.parent() is None
assert def_.docstring() assert def_.docstring()

View File

@@ -74,7 +74,7 @@ def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way,
follow_imports=True, follow_imports=True,
) )
if type_ == 'goto': if type_ == 'goto':
defs = [d for goto_def in goto_defs for d in goto_def.goto_assignments(**kwargs)] defs = [d for goto_def in goto_defs for d in goto_def.goto(**kwargs)]
else: else:
defs = [d for goto_def in goto_defs for d in goto_def.infer(**kwargs)] defs = [d for goto_def in goto_defs for d in goto_def.infer(**kwargs)]

View File

@@ -63,7 +63,7 @@ def test_keywords_variable(Script):
for seq in Script(code).goto_definitions(): for seq in Script(code).goto_definitions():
assert seq.name == 'Sequence' assert seq.name == 'Sequence'
# This points towards the typeshed implementation # This points towards the typeshed implementation
stub_seq, = seq.goto_assignments(only_stubs=True) stub_seq, = seq.goto(only_stubs=True)
assert typeshed.TYPESHED_PATH in stub_seq.module_path assert typeshed.TYPESHED_PATH in stub_seq.module_path
@@ -156,12 +156,12 @@ def test_math_is_stub(Script, code, full_name):
wanted = os.path.join('typeshed', 'stdlib', '2and3', 'math.pyi') wanted = os.path.join('typeshed', 'stdlib', '2and3', 'math.pyi')
assert cos.module_path.endswith(wanted) assert cos.module_path.endswith(wanted)
assert cos.is_stub() is True assert cos.is_stub() is True
assert cos.goto_assignments(only_stubs=True) == [cos] assert cos.goto(only_stubs=True) == [cos]
assert cos.full_name == full_name assert cos.full_name == full_name
cos, = s.goto_assignments() cos, = s.goto_assignments()
assert cos.module_path.endswith(wanted) assert cos.module_path.endswith(wanted)
assert cos.goto_assignments(only_stubs=True) == [cos] assert cos.goto(only_stubs=True) == [cos]
assert cos.is_stub() is True assert cos.is_stub() is True
assert cos.full_name == full_name assert cos.full_name == full_name
@@ -171,7 +171,7 @@ def test_goto_stubs(Script):
os_module, = s.goto_definitions() os_module, = s.goto_definitions()
assert os_module.full_name == 'os' assert os_module.full_name == 'os'
assert os_module.is_stub() is False assert os_module.is_stub() is False
stub, = os_module.goto_assignments(only_stubs=True) stub, = os_module.goto(only_stubs=True)
assert stub.is_stub() is True assert stub.is_stub() is True
os_module, = s.goto_assignments() os_module, = s.goto_assignments()
@@ -202,7 +202,7 @@ def test_goto_stubs_on_itself(Script, code, type_):
def_, = s.goto_definitions() def_, = s.goto_definitions()
else: else:
def_, = s.goto_assignments(follow_imports=True) def_, = s.goto_assignments(follow_imports=True)
stub, = def_.goto_assignments(only_stubs=True) stub, = def_.goto(only_stubs=True)
script_on_source = Script( script_on_source = Script(
path=def_.module_path, path=def_.module_path,
@@ -213,7 +213,7 @@ def test_goto_stubs_on_itself(Script, code, type_):
definition, = script_on_source.goto_definitions() definition, = script_on_source.goto_definitions()
else: else:
definition, = script_on_source.goto_assignments() definition, = script_on_source.goto_assignments()
same_stub, = definition.goto_assignments(only_stubs=True) same_stub, = definition.goto(only_stubs=True)
_assert_is_same(same_stub, stub) _assert_is_same(same_stub, stub)
_assert_is_same(definition, def_) _assert_is_same(definition, def_)
assert same_stub.module_path != def_.module_path assert same_stub.module_path != def_.module_path
@@ -230,7 +230,7 @@ def test_goto_stubs_on_itself(Script, code, type_):
same_definition2, = same_stub.infer() same_definition2, = same_stub.infer()
else: else:
same_definition, = script_on_stub.goto_assignments() same_definition, = script_on_stub.goto_assignments()
same_definition2, = same_stub.goto_assignments() same_definition2, = same_stub.goto()
_assert_is_same(same_definition, definition) _assert_is_same(same_definition, definition)
_assert_is_same(same_definition, same_definition2) _assert_is_same(same_definition, same_definition2)