forked from VimPlug/jedi
Merge branch 'master' into typeddict
This commit is contained in:
@@ -209,11 +209,11 @@ if r:
|
||||
|
||||
deleted_var = 3
|
||||
del deleted_var
|
||||
#? int()
|
||||
#?
|
||||
deleted_var
|
||||
#? ['deleted_var']
|
||||
#? []
|
||||
deleted_var
|
||||
#! ['deleted_var = 3']
|
||||
#! []
|
||||
deleted_var
|
||||
|
||||
# -----------------
|
||||
|
||||
@@ -78,6 +78,28 @@ g = iter([1.0])
|
||||
#? float()
|
||||
next(g)
|
||||
|
||||
x, y = Get()
|
||||
#? int() str()
|
||||
x
|
||||
#? int() str()
|
||||
x
|
||||
|
||||
class Iter:
|
||||
def __iter__(self):
|
||||
yield ""
|
||||
i = 0
|
||||
while True:
|
||||
v = 1
|
||||
yield v
|
||||
i += 1
|
||||
a, b, c = Iter()
|
||||
#? str() int()
|
||||
a
|
||||
#? str() int()
|
||||
b
|
||||
#? str() int()
|
||||
c
|
||||
|
||||
|
||||
# -----------------
|
||||
# __next__
|
||||
@@ -134,7 +156,7 @@ a, b = simple()
|
||||
#? int() str()
|
||||
a
|
||||
# For now this is ok.
|
||||
#?
|
||||
#? int() str()
|
||||
b
|
||||
|
||||
|
||||
|
||||
@@ -436,6 +436,12 @@ def the_callable() -> float: ...
|
||||
#? float()
|
||||
call3_pls()(the_callable)[0]
|
||||
|
||||
def call4_pls(fn: typing.Callable[..., TYPE_VARX]) -> typing.Callable[..., TYPE_VARX]:
|
||||
return ""
|
||||
|
||||
#? int()
|
||||
call4_pls(lambda x: 1)()
|
||||
|
||||
# -------------------------
|
||||
# TYPE_CHECKING
|
||||
# -------------------------
|
||||
|
||||
@@ -558,3 +558,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()
|
||||
|
||||
@@ -112,7 +112,8 @@ def test_os_path(Script):
|
||||
|
||||
def test_os_issues(Script):
|
||||
"""Issue #873"""
|
||||
assert [c.name for c in Script('import os\nos.nt''').complete()] == ['nt']
|
||||
# nt is not found, because it's deleted
|
||||
assert [c.name for c in Script('import os\nos.nt''').complete()] == []
|
||||
|
||||
|
||||
def test_param_name(Script):
|
||||
|
||||
@@ -530,6 +530,16 @@ def test__wrapped__():
|
||||
assert c.line == syslogs_to_df.__wrapped__.__code__.co_firstlineno + 1
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
|
||||
def test_illegal_class_instance():
|
||||
class X:
|
||||
__class__ = 1
|
||||
X.__name__ = 'asdf'
|
||||
d, = jedi.Interpreter('foo', [{'foo': X()}]).infer()
|
||||
v, = d._name.infer()
|
||||
assert not v.is_instance()
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
|
||||
@pytest.mark.parametrize('module_name', ['sys', 'time', 'unittest.mock'])
|
||||
def test_core_module_completes(module_name):
|
||||
|
||||
@@ -62,3 +62,11 @@ def test_goto_import(Script, skip_pre_python35):
|
||||
assert d.is_stub()
|
||||
d, = Script(code).goto()
|
||||
assert not d.is_stub()
|
||||
|
||||
|
||||
def test_os_stat_result(Script):
|
||||
d, = Script('import os; os.stat_result').goto()
|
||||
assert d.is_stub()
|
||||
n = d._name
|
||||
# This should not be a different stub name
|
||||
assert convert_names([n]) == [n]
|
||||
|
||||
Reference in New Issue
Block a user