diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 945d5284..edc6374b 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -525,7 +525,7 @@ class Completion(BaseDefinition): class Definition(BaseDefinition): """ - *Definition* objects are returned from :meth:`api.Script.goto_assignments` + *Definition* objects are returned from :meth:`api.Script.goto` or :meth:`api.Script.infer`. """ def __init__(self, inference_state, definition): diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 996c67ba..4cd18660 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -166,7 +166,7 @@ def inline(script): dct = {} - definitions = script.goto_assignments() + definitions = script.goto() assert len(definitions) == 1 stmt = definitions[0]._definition usages = script.usages() diff --git a/test/completion/goto.py b/test/completion/goto.py index 029c59cb..3deabf33 100644 --- a/test/completion/goto.py +++ b/test/completion/goto.py @@ -1,4 +1,4 @@ -# goto_assignments command tests are different in syntax +# goto command tests are different in syntax definition = 3 #! 0 ['a = definition'] diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index b504cf85..eb67e23e 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -123,11 +123,11 @@ def test_completion_on_complex_literals(Script): {'if', 'and', 'in', 'is', 'not', 'or'}) -def test_goto_assignments_on_non_name(Script, environment): - assert Script('for').goto_assignments() == [] +def test_goto_non_name(Script, environment): + assert Script('for').goto() == [] - assert Script('assert').goto_assignments() == [] - assert Script('True').goto_assignments() == [] + assert Script('assert').goto() == [] + assert Script('True').goto() == [] def test_infer_on_non_name(Script): @@ -197,23 +197,23 @@ def test_get_line_code_on_builtin(Script, disable_typeshed): assert abs_.line is None -def test_goto_assignments_follow_imports(Script): +def test_goto_follow_imports(Script): code = dedent(""" import inspect inspect.isfunction""") - definition, = Script(code, column=0).goto_assignments(follow_imports=True) + definition, = Script(code).goto(column=0, follow_imports=True) assert 'inspect.py' in definition.module_path assert (definition.line, definition.column) == (1, 0) - definition, = Script(code).goto_assignments(follow_imports=True) + definition, = Script(code).goto(follow_imports=True) assert 'inspect.py' in definition.module_path assert (definition.line, definition.column) > (1, 0) code = '''def param(p): pass\nparam(1)''' start_pos = 1, len('def param(') - script = Script(code, *start_pos) - definition, = script.goto_assignments(follow_imports=True) + script = Script(code) + definition, = script.goto(*start_pos, follow_imports=True) assert (definition.line, definition.column) == start_pos assert definition.name == 'p' result, = definition.goto() @@ -223,17 +223,17 @@ def test_goto_assignments_follow_imports(Script): result, = result.infer() assert result.name == 'int' - definition, = script.goto_assignments() + definition, = script.goto(*start_pos) assert (definition.line, definition.column) == start_pos - d, = Script('a = 1\na').goto_assignments(follow_imports=True) + d, = Script('a = 1\na').goto(follow_imports=True) assert d.name == 'a' def test_goto_module(Script): def check(line, expected, follow_imports=False): - script = Script(path=path, line=line) - module, = script.goto_assignments(follow_imports=follow_imports) + script = Script(path=path) + module, = script.goto(line=line, follow_imports=follow_imports) assert module.module_path == expected base_path = os.path.join(os.path.dirname(__file__), 'simple_import') @@ -309,9 +309,9 @@ def test_backslash_continuation_and_bracket(Script): def test_goto_follow_builtin_imports(Script): s = Script('import sys; sys') - d, = s.goto_assignments(follow_imports=True) + d, = s.goto(follow_imports=True) assert d.in_builtin_module() is True - d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True) + d, = s.goto(follow_imports=True, follow_builtin_imports=True) assert d.in_builtin_module() is True diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index 6ec9f90b..bc3055ac 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -55,8 +55,8 @@ def test_basedefinition_type(Script, names): definitions += script2.usages() source_param = "def f(a): return a" - script_param = Script(source_param, 1, len(source_param), None) - definitions += script_param.goto_assignments() + script_param = Script(source_param, path=None) + definitions += script_param.goto(1, len(source_param)) return definitions @@ -118,7 +118,7 @@ def test_class_call_signature(Script): def test_position_none_if_builtin(Script): - gotos = Script('import sys; sys.path').goto_assignments() + gotos = Script('import sys; sys.path').goto() assert gotos[0].in_builtin_module() assert gotos[0].line is not None assert gotos[0].column is not None @@ -206,8 +206,8 @@ def test_signature_params(Script): check(Script(s).infer()) - check(Script(s).goto_assignments()) - check(Script(s + '\nbar=foo\nbar').goto_assignments()) + check(Script(s).goto()) + check(Script(s + '\nbar=foo\nbar').goto()) def test_param_endings(Script): @@ -253,7 +253,7 @@ def test_is_definition_import(names, code, expected): def test_parent(Script): def _parent(source, line=None, column=None): - def_, = Script(dedent(source), line, column).goto_assignments() + def_, = Script(dedent(source)).goto(line, column) return def_.parent() parent = _parent('foo=1\nfoo') @@ -270,7 +270,7 @@ def test_parent(Script): def test_parent_on_function(Script): code = 'def spam():\n pass' - def_, = Script(code, line=1, column=len('def spam')).goto_assignments() + def_, = Script(code).goto(line=1, column=len('def spam')) parent = def_.parent() assert parent.name == '' assert parent.type == 'module' @@ -328,13 +328,13 @@ def test_type_II(Script): """ -This tests the BaseDefinition.goto_assignments function, not the jedi +This tests the BaseDefinition.goto function, not the jedi function. They are not really different in functionality, but really different as an implementation. """ -def test_goto_assignment_repetition(names): +def test_goto_repetition(names): defs = names('a = 1; a', references=True, definitions=False) # Repeat on the same variable. Shouldn't change once we're on a # definition. @@ -344,7 +344,7 @@ def test_goto_assignment_repetition(names): assert ass[0].description == 'a = 1' -def test_goto_assignments_named_params(names): +def test_goto_named_params(names): src = """\ def foo(a=1, bar=2): pass @@ -468,7 +468,7 @@ def test_builtin_module_with_path(Script): ] ) def test_execute(Script, code, description): - definition, = Script(code).goto_assignments() + definition, = Script(code).goto() definitions = definition.execute() if description is None: assert not definitions @@ -477,7 +477,7 @@ def test_execute(Script, code, description): assert d.description == description -@pytest.mark.parametrize('goto_assignment', [False, True, None]) +@pytest.mark.parametrize('goto', [False, True, None]) @pytest.mark.parametrize( 'code, name, file_name', [ ('from pkg import Foo; Foo.foo', 'foo', '__init__.py'), @@ -485,15 +485,15 @@ def test_execute(Script, code, description): ('from pkg import Foo; Foo.bar', 'bar', 'module.py'), ('from pkg import Foo; Foo().bar', 'bar', 'module.py'), ]) -def test_inheritance_module_path(Script, goto_assignment, code, name, file_name): +def test_inheritance_module_path(Script, goto, code, name, file_name): base_path = os.path.join(get_example_dir('inheritance'), 'pkg') whatever_path = os.path.join(base_path, 'NOT_EXISTING.py') script = Script(code, path=whatever_path) - if goto_assignment is None: + if goto is None: func, = script.infer() else: - func, = script.goto_assignments(follow_imports=goto_assignment) + func, = script.goto(follow_imports=goto) assert func.type == 'function' assert func.name == name assert func.module_path == os.path.join(base_path, file_name) diff --git a/test/test_api/test_keyword.py b/test/test_api/test_keyword.py index 6861d628..3e5b9344 100644 --- a/test/test_api/test_keyword.py +++ b/test/test_api/test_keyword.py @@ -5,13 +5,13 @@ Test of keywords and ``jedi.keywords`` import pytest -def test_goto_assignments_keyword(Script): +def test_goto_keyword(Script): """ Bug: goto assignments on ``in`` used to raise AttributeError:: 'unicode' object has no attribute 'generate_call_path' """ - Script('in').goto_assignments() + Script('in').goto() def test_keyword(Script, environment): @@ -22,7 +22,7 @@ def test_keyword(Script, environment): else: assert [d.docstring() for d in defs] - assert Script("import").goto_assignments() == [] + assert Script("import").goto() == [] completions = Script("import").complete(1, 1) assert len(completions) > 10 and 'if' in [c.name for c in completions] diff --git a/test/test_api/test_signatures.py b/test/test_api/test_signatures.py index 93bebb0b..c00572b8 100644 --- a/test/test_api/test_signatures.py +++ b/test/test_api/test_signatures.py @@ -21,7 +21,7 @@ _tuple_code = 'from typing import Tuple\ndef f(x: Tuple[int]): ...\nf' ] ) def test_param_annotation(Script, code, expected_params, execute_annotation, skip_python2): - func, = Script(code).goto_assignments() + func, = Script(code).goto() sig, = func.get_signatures() for p, expected in zip(sig.params, expected_params): annotations = p.infer_annotation(execute_annotation=execute_annotation) @@ -40,7 +40,7 @@ def test_param_annotation(Script, code, expected_params, execute_annotation, ski ] ) def test_param_default(Script, code, expected_params): - func, = Script(code).goto_assignments() + func, = Script(code).goto() sig, = func.get_signatures() for p, expected in zip(sig.params, expected_params): annotations = p.infer_default() @@ -62,7 +62,7 @@ def test_param_default(Script, code, expected_params): ] ) def test_param_kind_and_name(code, index, param_code, kind, Script, skip_python2): - func, = Script(code).goto_assignments() + func, = Script(code).goto() sig, = func.get_signatures() param = sig.params[index] assert param.to_string() == param_code diff --git a/test/test_inference/test_gradual/test_conversion.py b/test/test_inference/test_gradual/test_conversion.py index 00e76935..1e05e5cc 100644 --- a/test/test_inference/test_gradual/test_conversion.py +++ b/test/test_inference/test_gradual/test_conversion.py @@ -28,11 +28,11 @@ def test_sqlite3_conversion(Script): def test_conversion_of_stub_only(Script): project = Project(os.path.join(root_dir, 'test', 'completion', 'stub_folder')) code = 'import stub_only; stub_only.in_stub_only' - d1, = Script(code, _project=project).goto_assignments() + d1, = Script(code, _project=project).goto() assert d1.is_stub() - script = Script(path=d1.module_path, line=d1.line, column=d1.column, _project=project) - d2, = script.goto_assignments() + script = Script(path=d1.module_path, _project=project) + d2, = script.goto(line=d1.line, column=d1.column) assert d2.is_stub() assert d2.module_path == d1.module_path assert d2.line == d1.line @@ -43,7 +43,7 @@ def test_conversion_of_stub_only(Script): def test_goto_on_file(Script): project = Project(os.path.join(root_dir, 'test', 'completion', 'stub_folder')) script = Script('import stub_only; stub_only.Foo', _project=project) - d1, = script.goto_assignments() + d1, = script.goto() v, = d1._name.infer() foo, bar, obj = v.py__mro__() assert foo.py__name__() == 'Foo' @@ -51,6 +51,6 @@ def test_goto_on_file(Script): assert obj.py__name__() == 'object' # Make sure we go to Bar, because Foo is a bit before: `class Foo(Bar):` - script = Script(path=d1.module_path, line=d1.line, column=d1.column + 4, _project=project) - d2, = script.goto_assignments() + script = Script(path=d1.module_path, _project=project) + d2, = script.goto(line=d1.line, column=d1.column + 4) assert d2.name == 'Bar' diff --git a/test/test_inference/test_gradual/test_stubs.py b/test/test_inference/test_gradual/test_stubs.py index c8910060..8d7bdb02 100644 --- a/test/test_inference/test_gradual/test_stubs.py +++ b/test/test_inference/test_gradual/test_stubs.py @@ -64,11 +64,11 @@ def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way, if way == 'direct': if type_ == 'goto': - defs = s.goto_assignments(follow_imports=True, **kwargs) + defs = s.goto(follow_imports=True, **kwargs) else: defs = s.infer(**kwargs) else: - goto_defs = s.goto_assignments( + goto_defs = s.goto( # Prefering stubs when we want to go to python and vice versa prefer_stubs=not (prefer_stubs or only_stubs), follow_imports=True, diff --git a/test/test_inference/test_gradual/test_typeshed.py b/test/test_inference/test_gradual/test_typeshed.py index 91e19a9a..a3076bdc 100644 --- a/test/test_inference/test_gradual/test_typeshed.py +++ b/test/test_inference/test_gradual/test_typeshed.py @@ -159,7 +159,7 @@ def test_math_is_stub(Script, code, full_name): assert cos.goto(only_stubs=True) == [cos] assert cos.full_name == full_name - cos, = s.goto_assignments() + cos, = s.goto() assert cos.module_path.endswith(wanted) assert cos.goto(only_stubs=True) == [cos] assert cos.is_stub() is True @@ -174,7 +174,7 @@ def test_goto_stubs(Script): stub, = os_module.goto(only_stubs=True) assert stub.is_stub() is True - os_module, = s.goto_assignments() + os_module, = s.goto() def _assert_is_same(d1, d2): @@ -201,7 +201,7 @@ def test_goto_stubs_on_itself(Script, code, type_): if type_ == 'infer': def_, = s.infer() else: - def_, = s.goto_assignments(follow_imports=True) + def_, = s.goto(follow_imports=True) stub, = def_.goto(only_stubs=True) script_on_source = Script(path=def_.module_path) diff --git a/test/test_inference/test_implicit_namespace_package.py b/test/test_inference/test_implicit_namespace_package.py index 020e95f1..d8983cad 100644 --- a/test/test_inference/test_implicit_namespace_package.py +++ b/test/test_inference/test_implicit_namespace_package.py @@ -27,7 +27,7 @@ def test_implicit_namespace_package(Script): 'from pkg.ns1_file import foo': 'ns1_file!', } for source, solution in tests.items(): - ass = script_with_path(source).goto_assignments() + ass = script_with_path(source).goto() assert len(ass) == 1 assert ass[0].description == "foo = '%s'" % solution diff --git a/test/test_inference/test_imports.py b/test/test_inference/test_imports.py index c0a88cef..f7ec0ebc 100644 --- a/test/test_inference/test_imports.py +++ b/test/test_inference/test_imports.py @@ -244,13 +244,13 @@ def test_named_import(Script): @pytest.mark.skipif('True', reason='The nested import stuff is still very messy.') def test_goto_following_on_imports(Script): s = "import multiprocessing.dummy; multiprocessing.dummy" - g = Script(s).goto_assignments() + g = Script(s).goto() assert len(g) == 1 assert (g[0].line, g[0].column) != (0, 0) -def test_goto_assignments(Script): - sys, = Script("import sys", 1, 10).goto_assignments(follow_imports=True) +def test_goto(Script): + sys, = Script("import sys", 1, 10).goto(follow_imports=True) assert sys.type == 'module'