mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Test infer_annotation
This commit is contained in:
@@ -613,7 +613,7 @@ class Signature(Definition):
|
||||
return the `isinstance` function. without `(` it would return nothing.
|
||||
"""
|
||||
def __init__(self, evaluator, signature):
|
||||
super(CallSignature, self).__init__(evaluator, signature.name)
|
||||
super(Signature, self).__init__(evaluator, signature.name)
|
||||
self._signature = signature
|
||||
|
||||
@property
|
||||
@@ -665,7 +665,11 @@ class ParamDefinition(Definition):
|
||||
return [Definition(self._evaluator, d.name) for d in self._name.infer_default()]
|
||||
|
||||
def infer_annotation(self):
|
||||
return [Definition(self._evaluator, d.name) for d in self._name.infer_annotation()]
|
||||
return [Definition(self._evaluator, d.name)
|
||||
for d in self._name.infer_annotation().execute_annotation()]
|
||||
|
||||
def to_string(self):
|
||||
return self._name.to_string()
|
||||
|
||||
|
||||
def _format_signatures(context):
|
||||
|
||||
21
test/test_api/test_signatures.py
Normal file
21
test/test_api/test_signatures.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code, expected_params', [
|
||||
('def f(x: 1, y): ...\nf', [None, None]),
|
||||
('def f(x: int): ...\nf', ['instance int']),
|
||||
('from typing import List\ndef f(x: List[int]): ...\nf', ['instance list']),
|
||||
('from typing import Tuple\ndef f(x: Tuple[int]): ...\nf', ['Tuple: _SpecialForm = ...']),
|
||||
('x=str\ndef f(p: x): ...\nx=int\nf', ['instance int']),
|
||||
]
|
||||
)
|
||||
def test_param_annotation(Script, code, expected_params):
|
||||
func, = Script(code).goto_assignments()
|
||||
sig, = func.get_signatures()
|
||||
for p, expected in zip(sig.params, expected_params):
|
||||
if expected is None:
|
||||
assert not p.infer_annotation()
|
||||
else:
|
||||
annotation, = p.infer_annotation()
|
||||
assert annotation.description == expected
|
||||
Reference in New Issue
Block a user