1
0
forked from VimPlug/jedi

Merge branch 'master' into project

This commit is contained in:
Dave Halter
2020-02-03 09:26:43 +01:00
18 changed files with 182 additions and 14 deletions

View File

@@ -559,3 +559,43 @@ def test_definition_goto_follow_imports(Script):
assert follow.description == 'def dumps'
assert follow.line != 1
assert follow.module_name == 'json'
@pytest.mark.parametrize(
'code, expected', [
('1', 'int'),
('x = None; x', 'None'),
('n: Optional[str]; n', 'Optional[str]'),
('n = None if xxxxx else ""; n', 'Optional[str]'),
('n = None if xxxxx else str(); n', 'Optional[str]'),
('n = None if xxxxx else str; n', 'Optional[Type[str]]'),
('class Foo: pass\nFoo', 'Type[Foo]'),
('class Foo: pass\nFoo()', 'Foo'),
('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]'),
('n = [1]; n', 'List[int]'),
('n = [1, ""]; n', 'List[Union[int, str]]'),
('n = [1, str(), None]; n', 'List[Optional[Union[int, str]]]'),
('n = {1, str()}; n', 'Set[Union[int, str]]'),
('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_pre_python36):
code = 'from typing import *\n' + code
d, = Script(code).goto()
assert d.get_type_hint() == expected