forked from VimPlug/jedi
Merge branch 'master' into project
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -431,8 +431,9 @@ def test_completion_cache(Script, module_injector):
|
||||
assert cls.docstring() == 'foo()\n\ndoc2'
|
||||
|
||||
|
||||
def test_typing_module_completions(Script):
|
||||
for c in Script('import typing; typing.').completions():
|
||||
@pytest.mark.parametrize('module', ['typing', 'os'])
|
||||
def test_module_completions(Script, module):
|
||||
for c in Script('import {module}; {module}.'.format(module=module)).completions():
|
||||
# Just make sure that there are no errors
|
||||
c.type
|
||||
c.docstring()
|
||||
|
||||
Reference in New Issue
Block a user