Make sure param hints are working for functions

This commit is contained in:
Dave Halter
2020-02-02 18:36:56 +01:00
parent 4c7179bc87
commit e3c4b5b77e
3 changed files with 44 additions and 1 deletions

View File

@@ -573,6 +573,7 @@ def test_definition_goto_follow_imports(Script):
('n: Type[List[int]]; n', 'Type[List[int]]'),
('n: Type[List]; n', 'Type[list]'),
('n: List; n', 'list'),
('n: List[int]; n', 'List[int]'),
('n: Iterable[int]; n', 'Iterable[int]'),
@@ -583,9 +584,17 @@ def test_definition_goto_follow_imports(Script):
('n = (1,); n', 'Tuple[int]'),
('n = {1: ""}; n', 'Dict[int, str]'),
('n = {1: "", 1.0: b""}; n', 'Dict[Union[float, int], Union[bytes, str]]'),
('n = next; n', 'Union[next(__i: Iterator[_T]) -> _T, '
'next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]]'),
('abs', 'abs(__n: SupportsAbs[_T]) -> _T'),
('def foo(x, y): return x if xxxx else y\nfoo(str(), 1)\nfoo',
'foo(x: str, y: int) -> Union[int, str]'),
('def foo(x, y = None): return x if xxxx else y\nfoo(str(), 1)\nfoo',
'foo(x: str, y: int=None) -> Union[int, str]'),
]
)
def test_get_type_hint(Script, code, expected, skip_python2):
def test_get_type_hint(Script, code, expected, skip_pre_python35):
code = 'from typing import *\n' + code
d, = Script(code).goto()
assert d.get_type_hint() == expected