mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-30 08:44:21 +08:00
call signature -> signature
This commit is contained in:
@@ -6,12 +6,12 @@ import pytest
|
||||
|
||||
from ..helpers import TestCase
|
||||
from jedi import cache
|
||||
from jedi.parser_utils import get_call_signature
|
||||
from jedi.parser_utils import get_signature
|
||||
from jedi import Interpreter
|
||||
|
||||
|
||||
def assert_signature(Script, source, expected_name, expected_index=0, line=None, column=None):
|
||||
signatures = Script(source, line, column).call_signatures()
|
||||
signatures = Script(source).find_signatures(line, column)
|
||||
|
||||
assert len(signatures) <= 1
|
||||
|
||||
@@ -96,12 +96,12 @@ class TestSignatures(TestCase):
|
||||
|
||||
def test_with(Script):
|
||||
# jedi-vim #9
|
||||
sigs = Script("with open(").call_signatures()
|
||||
sigs = Script("with open(").find_signatures()
|
||||
assert sigs
|
||||
assert all(sig.name == 'open' for sig in sigs)
|
||||
|
||||
|
||||
def test_call_signatures_empty_parentheses_pre_space(Script):
|
||||
def test_find_signatures_empty_parentheses_pre_space(Script):
|
||||
s = dedent("""\
|
||||
def f(a, b):
|
||||
pass
|
||||
@@ -118,10 +118,10 @@ def test_multiple_signatures(Script):
|
||||
def f(a, b):
|
||||
pass
|
||||
f(""")
|
||||
assert len(Script(s).call_signatures()) == 2
|
||||
assert len(Script(s).find_signatures()) == 2
|
||||
|
||||
|
||||
def test_call_signatures_whitespace(Script):
|
||||
def test_find_signatures_whitespace(Script):
|
||||
s = dedent("""\
|
||||
abs(
|
||||
def x():
|
||||
@@ -148,7 +148,7 @@ def test_decorator_in_class(Script):
|
||||
|
||||
C().test(""")
|
||||
|
||||
signatures = Script(s).call_signatures()
|
||||
signatures = Script(s).find_signatures()
|
||||
assert len(signatures) == 1
|
||||
x = [p.description for p in signatures[0].params]
|
||||
assert x == ['param *args']
|
||||
@@ -176,14 +176,14 @@ def test_brackets_in_string_literals(Script):
|
||||
def test_function_definitions_should_break(Script):
|
||||
"""
|
||||
Function definitions (and other tokens that cannot exist within call
|
||||
signatures) should break and not be able to return a call signature.
|
||||
signatures) should break and not be able to return a signature.
|
||||
"""
|
||||
assert_signature(Script, 'abs(\ndef x', 'abs', 0)
|
||||
assert not Script('abs(\ndef x(): pass').call_signatures()
|
||||
assert not Script('abs(\ndef x(): pass').find_signatures()
|
||||
|
||||
|
||||
def test_flow_call(Script):
|
||||
assert not Script('if (1').call_signatures()
|
||||
assert not Script('if (1').find_signatures()
|
||||
|
||||
|
||||
def test_chained_calls(Script):
|
||||
@@ -209,11 +209,11 @@ def test_return(Script):
|
||||
assert_signature(Script, source, 'join', 0, column=len(" return '.'.join("))
|
||||
|
||||
|
||||
def test_call_signature_on_module(Script):
|
||||
def test_find_signature_on_module(Script):
|
||||
"""github issue #240"""
|
||||
s = 'import datetime; datetime('
|
||||
# just don't throw an exception (if numpy doesn't exist, just ignore it)
|
||||
assert Script(s).call_signatures() == []
|
||||
assert Script(s).find_signatures() == []
|
||||
|
||||
|
||||
def test_complex(Script, environment):
|
||||
@@ -234,7 +234,7 @@ def test_complex(Script, environment):
|
||||
re.compile(
|
||||
return it * 2
|
||||
"""
|
||||
sig1, sig2 = sorted(Script(s, line=4, column=27).call_signatures(), key=lambda s: s.line)
|
||||
sig1, sig2 = sorted(Script(s).find_signatures(line=4, column=27), key=lambda s: s.line)
|
||||
assert sig1.name == sig2.name == 'compile'
|
||||
assert sig1.index == sig2.index == 0
|
||||
func1, = sig1._name.infer()
|
||||
@@ -243,14 +243,14 @@ def test_complex(Script, environment):
|
||||
if environment.version_info.major == 3:
|
||||
# Do these checks just for Python 3, I'm too lazy to deal with this
|
||||
# legacy stuff. ~ dave.
|
||||
assert get_call_signature(func1.tree_node) \
|
||||
assert get_signature(func1.tree_node) \
|
||||
== 'compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]'
|
||||
assert get_call_signature(func2.tree_node) \
|
||||
assert get_signature(func2.tree_node) \
|
||||
== 'compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) ->\nPattern[AnyStr]'
|
||||
|
||||
# jedi-vim #70
|
||||
s = """def foo("""
|
||||
assert Script(s).call_signatures() == []
|
||||
assert Script(s).find_signatures() == []
|
||||
|
||||
# jedi-vim #116
|
||||
s = """import itertools; test = getattr(itertools, 'chain'); test("""
|
||||
@@ -258,13 +258,13 @@ def test_complex(Script, environment):
|
||||
|
||||
|
||||
def _params(Script, source, line=None, column=None):
|
||||
signatures = Script(source, line, column).call_signatures()
|
||||
signatures = Script(source, line, column).find_signatures()
|
||||
assert len(signatures) == 1
|
||||
return signatures[0].params
|
||||
|
||||
|
||||
def test_int_params(Script):
|
||||
sig1, sig2 = Script('int(').call_signatures()
|
||||
sig1, sig2 = Script('int(').find_signatures()
|
||||
# int is defined as: `int(x[, base])`
|
||||
assert len(sig1.params) == 1
|
||||
assert sig1.params[0].name == 'x'
|
||||
@@ -275,13 +275,13 @@ def test_int_params(Script):
|
||||
|
||||
def test_pow_params(Script):
|
||||
# See Github #1357.
|
||||
for sig in Script('pow(').call_signatures():
|
||||
for sig in Script('pow(').find_signatures():
|
||||
param_names = [p.name for p in sig.params]
|
||||
assert param_names in (['x', 'y'], ['x', 'y', 'z'])
|
||||
|
||||
|
||||
def test_param_name(Script):
|
||||
sigs = Script('open(something,').call_signatures()
|
||||
sigs = Script('open(something,').find_signatures()
|
||||
for sig in sigs:
|
||||
# All of the signatures (in Python the function is overloaded),
|
||||
# contain the same param names.
|
||||
@@ -304,11 +304,11 @@ def test_builtins(Script):
|
||||
|
||||
def test_signature_is_definition(Script):
|
||||
"""
|
||||
Through inheritance, a call signature is a sub class of Definition.
|
||||
Through inheritance, a signature is a sub class of Definition.
|
||||
Check if the attributes match.
|
||||
"""
|
||||
s = """class Spam(): pass\nSpam"""
|
||||
signature = Script(s + '(').call_signatures()[0]
|
||||
signature = Script(s + '(').find_signatures()[0]
|
||||
definition = Script(s + '(').infer(column=0)[0]
|
||||
signature.line == 1
|
||||
signature.column == 6
|
||||
@@ -330,15 +330,15 @@ def test_signature_is_definition(Script):
|
||||
|
||||
def test_no_signature(Script):
|
||||
# str doesn't have a __call__ method
|
||||
assert Script('str()(').call_signatures() == []
|
||||
assert Script('str()(').find_signatures() == []
|
||||
|
||||
s = dedent("""\
|
||||
class X():
|
||||
pass
|
||||
X()(""")
|
||||
assert Script(s).call_signatures() == []
|
||||
assert len(Script(s, column=2).call_signatures()) == 1
|
||||
assert Script('').call_signatures() == []
|
||||
assert Script(s).find_signatures() == []
|
||||
assert len(Script(s).find_signatures(column=2)) == 1
|
||||
assert Script('').find_signatures() == []
|
||||
|
||||
|
||||
def test_dict_literal_in_incomplete_call(Script):
|
||||
@@ -354,24 +354,24 @@ def test_dict_literal_in_incomplete_call(Script):
|
||||
c = Foo()
|
||||
"""
|
||||
|
||||
script = Script(dedent(source), line=4, column=15)
|
||||
assert script.call_signatures()
|
||||
script = Script(dedent(source))
|
||||
assert script.find_signatures(line=4, column=15)
|
||||
|
||||
|
||||
def test_completion_interference(Script):
|
||||
"""Seems to cause problems, see also #396."""
|
||||
cache.parser_cache.pop(None, None)
|
||||
assert Script('open(').call_signatures()
|
||||
assert Script('open(').find_signatures()
|
||||
|
||||
# complete something usual, before doing the same call_signatures again.
|
||||
# complete something usual, before doing the same find_signatures again.
|
||||
assert Script('from datetime import ').complete()
|
||||
|
||||
assert Script('open(').call_signatures()
|
||||
assert Script('open(').find_signatures()
|
||||
|
||||
|
||||
def test_keyword_argument_index(Script, environment):
|
||||
def get(source, column=None):
|
||||
return Script(source, column=column).call_signatures()[0]
|
||||
return Script(source).find_signatures(column=column)[0]
|
||||
|
||||
# The signature of sorted changed from 2 to 3.
|
||||
py2_offset = int(environment.version_info.major == 2)
|
||||
@@ -509,7 +509,7 @@ def test_signature_index(skip_python2, Script, environment, code, call, expected
|
||||
if environment.version_info < (3, 8):
|
||||
code = code.replace('/,', '')
|
||||
|
||||
sig, = Script(code + '\n' + call + ending, column=len(call)).call_signatures()
|
||||
sig, = Script(code + '\n' + call + ending).find_signatures(column=len(call))
|
||||
index = sig.index
|
||||
assert expected_index == index
|
||||
|
||||
@@ -547,14 +547,14 @@ def test_arg_defaults(Script, environment, code):
|
||||
yield Interpreter(code + '2(', namespaces=[executed_locals])
|
||||
|
||||
for script in iter_scripts():
|
||||
signatures = script.call_signatures()
|
||||
signatures = script.find_signatures()
|
||||
assert signatures[0].params[0].description in ('param arg="bla"', "param arg='bla'")
|
||||
assert signatures[0].params[1].description == 'param arg1=1'
|
||||
|
||||
|
||||
def test_bracket_start(Script):
|
||||
def bracket_start(src):
|
||||
signatures = Script(src).call_signatures()
|
||||
signatures = Script(src).find_signatures()
|
||||
assert len(signatures) == 1
|
||||
return signatures[0].bracket_start
|
||||
|
||||
@@ -564,7 +564,7 @@ def test_bracket_start(Script):
|
||||
def test_different_caller(Script):
|
||||
"""
|
||||
It's possible to not use names, but another function result or an array
|
||||
index and then get the call signature of it.
|
||||
index and then get the signature of it.
|
||||
"""
|
||||
|
||||
assert_signature(Script, '[abs][0](', 'abs', 0)
|
||||
@@ -579,14 +579,14 @@ def test_in_function(Script):
|
||||
class X():
|
||||
@property
|
||||
def func(''')
|
||||
assert not Script(code).call_signatures()
|
||||
assert not Script(code).find_signatures()
|
||||
|
||||
|
||||
def test_lambda_params(Script):
|
||||
code = dedent('''\
|
||||
my_lambda = lambda x: x+1
|
||||
my_lambda(1)''')
|
||||
sig, = Script(code, column=11).call_signatures()
|
||||
sig, = Script(code).find_signatures(column=11)
|
||||
assert sig.index == 0
|
||||
assert sig.name == '<lambda>'
|
||||
assert [p.name for p in sig.params] == ['x']
|
||||
@@ -601,19 +601,19 @@ class X():
|
||||
|
||||
def test_class_creation(Script):
|
||||
|
||||
sig, = Script(CLASS_CODE + 'X(').call_signatures()
|
||||
sig, = Script(CLASS_CODE + 'X(').find_signatures()
|
||||
assert sig.index == 0
|
||||
assert sig.name == 'X'
|
||||
assert [p.name for p in sig.params] == ['foo', 'bar']
|
||||
|
||||
|
||||
def test_call_init_on_class(Script):
|
||||
sig, = Script(CLASS_CODE + 'X.__init__(').call_signatures()
|
||||
sig, = Script(CLASS_CODE + 'X.__init__(').find_signatures()
|
||||
assert [p.name for p in sig.params] == ['self', 'foo', 'bar']
|
||||
|
||||
|
||||
def test_call_init_on_instance(Script):
|
||||
sig, = Script(CLASS_CODE + 'X().__init__(').call_signatures()
|
||||
sig, = Script(CLASS_CODE + 'X().__init__(').find_signatures()
|
||||
assert [p.name for p in sig.params] == ['foo', 'bar']
|
||||
|
||||
|
||||
@@ -623,14 +623,14 @@ def test_call_magic_method(Script):
|
||||
def __call__(self, baz):
|
||||
pass
|
||||
''')
|
||||
sig, = Script(code + 'X()(').call_signatures()
|
||||
sig, = Script(code + 'X()(').find_signatures()
|
||||
assert sig.index == 0
|
||||
assert sig.name == 'X'
|
||||
assert [p.name for p in sig.params] == ['baz']
|
||||
|
||||
sig, = Script(code + 'X.__call__(').call_signatures()
|
||||
sig, = Script(code + 'X.__call__(').find_signatures()
|
||||
assert [p.name for p in sig.params] == ['self', 'baz']
|
||||
sig, = Script(code + 'X().__call__(').call_signatures()
|
||||
sig, = Script(code + 'X().__call__(').find_signatures()
|
||||
assert [p.name for p in sig.params] == ['baz']
|
||||
|
||||
|
||||
@@ -642,9 +642,9 @@ def test_cursor_after_signature(Script, column):
|
||||
foo() # _
|
||||
""")
|
||||
|
||||
script = Script(source, 4, column)
|
||||
script = Script(source)
|
||||
|
||||
assert not script.call_signatures()
|
||||
assert not script.find_signatures(4, column)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -661,7 +661,7 @@ def test_cursor_after_signature(Script, column):
|
||||
]
|
||||
)
|
||||
def test_base_signatures(Script, code, line, column, name, index):
|
||||
sig, = Script(code, line=line, column=column).call_signatures()
|
||||
sig, = Script(code).find_signatures(line=line, column=column)
|
||||
|
||||
assert sig.name == name
|
||||
assert sig.index == index
|
||||
|
||||
@@ -92,7 +92,7 @@ def test_basedefinition_type_import(Script, src, expected_result, column):
|
||||
assert types == {expected_result}
|
||||
|
||||
|
||||
def test_function_call_signature_in_doc(Script):
|
||||
def test_function_signature_in_doc(Script):
|
||||
defs = Script("""
|
||||
def f(x, y=1, z='a'):
|
||||
pass
|
||||
@@ -107,7 +107,7 @@ def test_param_docstring(names):
|
||||
assert param.docstring() == ''
|
||||
|
||||
|
||||
def test_class_call_signature(Script):
|
||||
def test_class_signature(Script):
|
||||
defs = Script("""
|
||||
class Foo:
|
||||
def __init__(self, x, y=1, z='a'):
|
||||
@@ -215,7 +215,7 @@ def test_param_endings(Script):
|
||||
Params should be represented without the comma and whitespace they have
|
||||
around them.
|
||||
"""
|
||||
sig = Script('def x(a, b=5, c=""): pass\n x(').call_signatures()[0]
|
||||
sig = Script('def x(a, b=5, c=""): pass\n x(').find_signatures()[0]
|
||||
assert [p.description for p in sig.params] == ['param a', 'param b=5', 'param c=""']
|
||||
|
||||
|
||||
|
||||
@@ -548,7 +548,7 @@ def test_partial_signatures(code, expected, index):
|
||||
b = functools.partial(func, 1)
|
||||
c = functools.partial(func, 1, c=2)
|
||||
|
||||
sig, = jedi.Interpreter(code, [locals()]).call_signatures()
|
||||
sig, = jedi.Interpreter(code, [locals()]).find_signatures()
|
||||
assert sig.name == 'partial'
|
||||
assert [p.name for p in sig.params] == expected
|
||||
assert index == sig.index
|
||||
|
||||
@@ -70,5 +70,5 @@ def test_param_kind_and_name(code, index, param_code, kind, Script, skip_python2
|
||||
|
||||
|
||||
def test_staticmethod(Script):
|
||||
s, = Script('staticmethod(').call_signatures()
|
||||
s, = Script('staticmethod(').find_signatures()
|
||||
assert s.to_string() == 'staticmethod(f: Callable[..., Any])'
|
||||
|
||||
@@ -3,12 +3,12 @@ Test all things related to the ``jedi.cache`` module.
|
||||
"""
|
||||
|
||||
|
||||
def test_cache_call_signatures(Script):
|
||||
def test_cache_find_signatures(Script):
|
||||
"""
|
||||
See github issue #390.
|
||||
"""
|
||||
def check(column, call_name, path=None):
|
||||
assert Script(s, 1, column, path).call_signatures()[0].name == call_name
|
||||
assert Script(s, path=path).find_signatures(1, column)[0].name == call_name
|
||||
|
||||
s = 'str(int())'
|
||||
|
||||
@@ -26,4 +26,4 @@ def test_cache_call_signatures(Script):
|
||||
|
||||
def test_cache_line_split_issues(Script):
|
||||
"""Should still work even if there's a newline."""
|
||||
assert Script('int(\n').call_signatures()[0].name == 'int'
|
||||
assert Script('int(\n').find_signatures()[0].name == 'int'
|
||||
|
||||
@@ -422,5 +422,5 @@ def test_basic_str_init_signature(Script, disable_typeshed):
|
||||
class Foo(str):
|
||||
pass
|
||||
Foo(''')
|
||||
c, = Script(code).call_signatures()
|
||||
c, = Script(code).find_signatures()
|
||||
assert c.name == 'Foo'
|
||||
|
||||
@@ -13,7 +13,7 @@ def test_completions(Script):
|
||||
assert len(s.complete()) >= 15
|
||||
|
||||
|
||||
def test_call_signatures_extension(Script):
|
||||
def test_find_signatures_extension(Script):
|
||||
if os.name == 'nt':
|
||||
func = 'LoadLibrary'
|
||||
params = 1
|
||||
@@ -21,14 +21,14 @@ def test_call_signatures_extension(Script):
|
||||
func = 'dlopen'
|
||||
params = 2
|
||||
s = Script('import _ctypes; _ctypes.%s(' % (func,))
|
||||
sigs = s.call_signatures()
|
||||
sigs = s.find_signatures()
|
||||
assert len(sigs) == 1
|
||||
assert len(sigs[0].params) == params
|
||||
|
||||
|
||||
def test_call_signatures_stdlib(Script):
|
||||
def test_find_signatures_stdlib(Script):
|
||||
s = Script('import math; math.cos(')
|
||||
sigs = s.call_signatures()
|
||||
sigs = s.find_signatures()
|
||||
assert len(sigs) == 1
|
||||
assert len(sigs[0].params) == 1
|
||||
|
||||
|
||||
@@ -90,9 +90,9 @@ def test_tree_signature(Script, environment, code, expected):
|
||||
pytest.skip()
|
||||
|
||||
if expected is None:
|
||||
assert not Script(code).call_signatures()
|
||||
assert not Script(code).find_signatures()
|
||||
else:
|
||||
sig, = Script(code).call_signatures()
|
||||
sig, = Script(code).find_signatures()
|
||||
assert expected == sig.to_string()
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ def test_nested_signatures(Script, environment, combination, expected, skip_pre_
|
||||
super().foo(**kwargs)
|
||||
''')
|
||||
code += 'z = ' + combination + '\nz('
|
||||
sig, = Script(code).call_signatures()
|
||||
sig, = Script(code).find_signatures()
|
||||
computed = sig.to_string()
|
||||
if not re.match(r'\w+\(', expected):
|
||||
expected = '<lambda>(' + expected + ')'
|
||||
@@ -191,7 +191,7 @@ def test_nested_signatures(Script, environment, combination, expected, skip_pre_
|
||||
|
||||
def test_pow_signature(Script):
|
||||
# See github #1357
|
||||
sigs = Script('pow(').call_signatures()
|
||||
sigs = Script('pow(').find_signatures()
|
||||
strings = {sig.to_string() for sig in sigs}
|
||||
assert strings == {'pow(x: float, y: float, z: float, /) -> float',
|
||||
'pow(x: float, y: float, /) -> float',
|
||||
@@ -230,7 +230,7 @@ def test_pow_signature(Script):
|
||||
]
|
||||
)
|
||||
def test_wraps_signature(Script, code, signature, skip_pre_python35):
|
||||
sigs = Script(code).call_signatures()
|
||||
sigs = Script(code).find_signatures()
|
||||
assert {sig.to_string() for sig in sigs} == {signature}
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ def test_dataclass_signature(Script, skip_pre_python37, start, start_params):
|
||||
|
||||
code = 'from dataclasses import dataclass\n' + start + code
|
||||
|
||||
sig, = Script(code).call_signatures()
|
||||
sig, = Script(code).find_signatures()
|
||||
assert [p.name for p in sig.params] == start_params + ['name', 'price', 'quantity']
|
||||
quantity, = sig.params[-1].infer()
|
||||
assert quantity.name == 'int'
|
||||
@@ -289,13 +289,13 @@ def test_param_resolving_to_static(Script, stmt, expected, skip_pre_python35):
|
||||
def simple(a, b, *, c): ...
|
||||
full_redirect(simple)('''.format(stmt=stmt))
|
||||
|
||||
sig, = Script(code).call_signatures()
|
||||
sig, = Script(code).find_signatures()
|
||||
assert sig.to_string() == expected
|
||||
|
||||
|
||||
def test_overload(Script):
|
||||
dir_ = get_example_dir('typing_overload')
|
||||
code = 'from file import with_overload; with_overload('
|
||||
x1, x2 = Script(code, path=os.path.join(dir_, 'foo.py')).call_signatures()
|
||||
x1, x2 = Script(code, path=os.path.join(dir_, 'foo.py')).find_signatures()
|
||||
assert x1.to_string() == 'with_overload(x: int, y: int) -> float'
|
||||
assert x2.to_string() == 'with_overload(x: str, y: list) -> float'
|
||||
|
||||
@@ -6,7 +6,7 @@ from parso import parse
|
||||
|
||||
def test_form_feed_characters(Script):
|
||||
s = "\f\nclass Test(object):\n pass"
|
||||
Script(s, line=2, column=18).call_signatures()
|
||||
Script(s).find_signatures(line=2, column=18)
|
||||
|
||||
|
||||
def check_p(src):
|
||||
|
||||
@@ -62,13 +62,13 @@ def test_hex_values_in_docstring():
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code,call_signature', [
|
||||
'code,signature', [
|
||||
('def my_function(x, typed: Type, z):\n return', 'my_function(x, typed: Type, z)'),
|
||||
('def my_function(x, y, z) -> str:\n return', 'my_function(x, y, z) -> str'),
|
||||
('lambda x, y, z: x + y * z\n', '<lambda>(x, y, z)')
|
||||
])
|
||||
def test_get_call_signature(code, call_signature):
|
||||
def test_get_signature(code, signature):
|
||||
node = parse(code, version='3.5').children[0]
|
||||
if node.type == 'simple_stmt':
|
||||
node = node.children[0]
|
||||
assert parser_utils.get_call_signature(node) == call_signature
|
||||
assert parser_utils.get_signature(node) == signature
|
||||
|
||||
@@ -39,8 +39,8 @@ def test_os_path_join(Script):
|
||||
@_check_speed(0.15)
|
||||
def test_scipy_speed(Script):
|
||||
s = 'import scipy.weave; scipy.weave.inline('
|
||||
script = Script(s, 1, len(s), '')
|
||||
script.call_signatures()
|
||||
script = Script(s, path='')
|
||||
script.find_signatures(1, len(s))
|
||||
|
||||
|
||||
@_check_speed(0.8)
|
||||
|
||||
Reference in New Issue
Block a user