mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +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])'
|
||||
|
||||
Reference in New Issue
Block a user