mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Add a execute_annotation option to infer_annotation
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
import pytest
|
||||
|
||||
_tuple_code = 'from typing import Tuple\ndef f(x: Tuple[int]): ...\nf'
|
||||
|
||||
|
||||
@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']),
|
||||
'code, expected_params, execute_annotation', [
|
||||
('def f(x: 1, y): ...\nf', [None, None], True),
|
||||
('def f(x: 1, y): ...\nf', ['instance int', None], False),
|
||||
('def f(x: int): ...\nf', ['instance int'], True),
|
||||
('from typing import List\ndef f(x: List[int]): ...\nf', ['instance list'], True),
|
||||
('from typing import List\ndef f(x: List[int]): ...\nf', ['class list'], False),
|
||||
(_tuple_code, ['Tuple: _SpecialForm = ...'], True),
|
||||
(_tuple_code, ['Tuple: _SpecialForm = ...'], False),
|
||||
('x=str\ndef f(p: x): ...\nx=int\nf', ['instance int'], True),
|
||||
]
|
||||
)
|
||||
def test_param_annotation(Script, code, expected_params):
|
||||
def test_param_annotation(Script, code, expected_params, execute_annotation):
|
||||
func, = Script(code).goto_assignments()
|
||||
sig, = func.get_signatures()
|
||||
for p, expected in zip(sig.params, expected_params):
|
||||
annotations = p.infer_annotation(execute_annotation=execute_annotation)
|
||||
if expected is None:
|
||||
assert not p.infer_annotation()
|
||||
assert not annotations
|
||||
else:
|
||||
annotation, = p.infer_annotation()
|
||||
annotation, = annotations
|
||||
assert annotation.description == expected
|
||||
|
||||
Reference in New Issue
Block a user