1
0
forked from VimPlug/jedi

Merge branch 'master' into dict

This commit is contained in:
Dave Halter
2019-12-28 12:17:04 +01:00
153 changed files with 4231 additions and 1858 deletions

View File

@@ -45,6 +45,9 @@ b[int():]
#? list()
b[:]
#? 3
b[:]
#? int()
b[:, 1]
#? int()

View File

@@ -188,14 +188,31 @@ def init_global_var_predefined():
global_var_predefined
def global_as_import():
from import_tree import globals
#? ['foo']
globals.foo
#? int()
globals.foo
global r
r = r[r]
if r:
r += r + 2
#? int()
r
# -----------------
# within docstrs
# -----------------
def a():
"""
#? ['global_define']
#? []
global_define
#?
str
"""
pass
@@ -284,6 +301,56 @@ except MyException as e:
for x in e.my_attr:
pass
# -----------------
# params
# -----------------
my_param = 1
#? 9 str()
def foo1(my_param):
my_param = 3.0
foo1("")
my_type = float()
#? 20 float()
def foo2(my_param: my_type):
pass
foo2("")
#? 20 int()
def foo3(my_param=my_param):
pass
foo3("")
some_default = ''
#? []
def foo(my_t
#? []
def foo(my_t, my_ty
#? ['some_default']
def foo(my_t=some_defa
#? ['some_default']
def foo(my_t=some_defa, my_t2=some_defa
# python > 2.7
#? ['my_type']
def foo(my_t: lala=some_defa, my_t2: my_typ
#? ['my_type']
def foo(my_t: lala=some_defa, my_t2: my_typ
#? []
def foo(my_t: lala=some_defa, my_t
#? []
lambda my_t
#? []
lambda my_, my_t
#? ['some_default']
lambda x=some_defa
#? ['some_default']
lambda y, x=some_defa
# Just make sure we're not in some weird parsing recovery after opening brackets
def
# -----------------
# continuations
@@ -326,3 +393,19 @@ with open('') as f1, open('') as f2:
f1.closed
#? ['closed']
f2.closed
class Foo():
def __enter__(self):
return ''
#? 14 str()
with Foo() as f3:
#? str()
f3
#! 14 ['with Foo() as f3: f3']
with Foo() as f3:
f3
#? 6 Foo
with Foo() as f3:
f3

View File

@@ -382,6 +382,7 @@ getattr(getattr, 1)
getattr(str, [])
# python >= 3.5
class Base():
def ret(self, b):
return b
@@ -399,6 +400,12 @@ class Wrapper2():
#? int()
Wrapper(Base()).ret(3)
#? ['ret']
Wrapper(Base()).ret
#? int()
Wrapper(Wrapper(Base())).ret(3)
#? ['ret']
Wrapper(Wrapper(Base())).ret
#? int()
Wrapper2(Base()).ret(3)
@@ -409,6 +416,8 @@ class GetattrArray():
#? int()
GetattrArray().something[0]
#? []
GetattrArray().something
# -----------------
@@ -607,3 +616,17 @@ DefaultArg().y()
DefaultArg.x()
#? str()
DefaultArg.y()
# -----------------
# Error Recovery
# -----------------
from import_tree.pkg.base import MyBase
class C1(MyBase):
def f3(self):
#! 13 ['def f1']
self.f1() . # hey'''
#? 13 MyBase.f1
self.f1() . # hey'''

View File

@@ -20,7 +20,7 @@ tuple
class MyClass:
@pass_decorator
def x(foo,
#? 5 ["tuple"]
#? 5 []
tuple,
):
return 1

View File

@@ -0,0 +1,17 @@
# Exists only for completion/pytest.py
import pytest
@pytest.fixture()
def my_other_conftest_fixture():
return 1.0
@pytest.fixture()
def my_conftest_fixture(my_other_conftest_fixture):
return my_other_conftest_fixture
def my_not_existing_fixture():
return 3 # Just a normal function

View File

@@ -330,3 +330,16 @@ import abc
#? ['abstractmethod']
@abc.abstractmethod
# -----------------
# Goto
# -----------------
x = 1
#! 5 []
@x.foo()
def f(): pass
#! 1 ['x = 1']
@x.foo()
def f(): pass

View File

@@ -335,6 +335,11 @@ some_lst2[3]
#? int() str()
some_lst2[2]
some_lst3 = []
some_lst3[0] = 3
some_lst3[:] = '' # Is ignored for now.
#? int()
some_lst3[0]
# -----------------
# set setitem/other modifications (should not work)
# -----------------

View File

@@ -1,4 +1,4 @@
# goto_assignments command tests are different in syntax
# goto command tests are different in syntax
definition = 3
#! 0 ['a = definition']
@@ -37,6 +37,7 @@ foo = 10;print(foo)
# classes
# -----------------
class C(object):
x = 3
def b(self):
#! ['b = math']
b
@@ -44,8 +45,14 @@ class C(object):
self.b
#! 14 ['def b']
self.b()
#! 14 ['def b']
self.b.
#! 11 ['param self']
self.b
#! ['x = 3']
self.x
#! 14 ['x = 3']
self.x.
return 1
#! ['def b']

View File

@@ -0,0 +1,5 @@
def something():
global foo
foo = 3

View File

@@ -0,0 +1,3 @@
class MyBase:
def f1(self):
pass

View File

@@ -0,0 +1,76 @@
class Super(object):
attribute = 3
def func(self):
return 1
class Inner():
pass
class Sub(Super):
#? 13 Sub.attribute
def attribute(self):
pass
#! 8 ['attribute = 3']
def attribute(self):
pass
#! 4 ['def func']
func = 3
#! 12 ['def func']
class func(): pass
#! 8 ['class Inner']
def Inner(self): pass
# -----------------
# Finding self
# -----------------
class Test1:
class Test2:
def __init__(self):
self.foo_nested = 0
#? ['foo_nested']
self.foo_
#?
self.foo_here
def __init__(self, self2):
self.foo_here = 3
#? ['foo_here', 'foo_in_func']
self.foo_
#? int()
self.foo_here
#?
self.foo_nested
#?
self.foo_not_on_self
#? float()
self.foo_in_func
self2.foo_on_second = ''
def closure():
self.foo_in_func = 4.
def bar(self):
self = 3
self.foo_not_on_self = 3
class SubTest(Test1):
def __init__(self):
self.foo_sub_class = list
def bar(self):
#? ['foo_here', 'foo_in_func', 'foo_sub_class']
self.foo_
#? int()
self.foo_here
#?
self.foo_nested
#?
self.foo_not_on_self

View File

@@ -60,3 +60,32 @@ Test().test(blub=)
#? 12 []
any(iterable=)
def foo(xyz):
pass
#? 7 ['xyz']
foo(xyz)
# No completion should be possible if it's not a simple name
#? 17 []
x = " "; foo(x.xyz)
#? 17 []
x = " "; foo([xyz)
#? 20 []
x = " "; foo(z[f,xyz)
#? 18 []
x = " "; foo(z[xyz)
#? 20 []
x = " "; foo(xyz[xyz)
#? 20 []
x = " "; foo(xyz[(xyz)
#? 8 ['xyz']
@foo(xyz)
def x(): pass
@str
#? 8 ['xyz']
@foo(xyz)
def x(): pass

View File

@@ -1,5 +1,5 @@
def from_names():
#? ['mod1']
#? ['mod1', 'base']
from import_tree.pkg.
#? ['path']
from os.
@@ -20,8 +20,12 @@ def builtin_test():
#? ['sqlite3']
import sqlite3
#? ['classes']
# classes is a local module that has an __init__.py and can therefore not be
# found. test can be found.
#? []
import classes
#? ['test']
import test
#? ['timedelta']
from datetime import timedel
@@ -69,9 +73,9 @@ from import_tree.pkg import pkg
from import_tree.pkg.mod1 import not_existant, # whitespace before
#? ['a', 'foobar', '__name__', '__doc__', '__file__', '__package__']
from import_tree.pkg.mod1 import not_existant,
#? 22 ['mod1']
#? 22 ['mod1', 'base']
from import_tree.pkg. import mod1
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'classes', 'recurse_class1', 'recurse_class2', 'invisible_pkg', 'flow_import']
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'classes', 'globals', 'recurse_class1', 'recurse_class2', 'invisible_pkg', 'flow_import']
from import_tree. import pkg
#? 18 ['pkg']

View File

@@ -40,4 +40,4 @@ str(def
class Foo(object):
@property
#? ['str']
def bar(str
def bar(x=str

View File

@@ -44,7 +44,7 @@ def return_none() -> None:
"""
pass
#?
#? None
return_none()

View File

@@ -38,6 +38,20 @@ def test(a, b):
#? str()
e
class AA:
class BB:
pass
def test(a):
# type: (AA.BB) -> None
#? AA.BB()
a
def test(a):
# type: (AA.BB,) -> None
#? AA.BB()
a
a,b = 1, 2 # type: str, float
#? str()
a

View File

@@ -0,0 +1,74 @@
# python >= 3.6
from typing import List, Dict, overload
lst: list
list_alias: List
list_str: List[str]
list_str: List[int]
# -------------------------
# With base classes
# -------------------------
@overload
def overload_f2(value: List) -> str: ...
@overload
def overload_f2(value: Dict) -> int: ...
#? str()
overload_f2([''])
#? int()
overload_f2({1.0: 1.0})
#? str()
overload_f2(lst)
#? str()
overload_f2(list_alias)
#? str()
overload_f2(list_str)
@overload
def overload_f3(value: list) -> str: ...
@overload
def overload_f3(value: dict) -> float: ...
#? str()
overload_f3([''])
#? float()
overload_f3({1.0: 1.0})
#? str()
overload_f3(lst)
#? str()
overload_f3(list_alias)
#? str()
overload_f3(list_str)
# -------------------------
# Generics Matching
# -------------------------
@overload
def overload_f1(value: List[str]) -> str: ...
@overload
def overload_f1(value: Dict[str, str]) -> Dict[str, str]: ...
def overload_f1():
pass
#? str()
overload_f1([''])
#? str() dict()
overload_f1(1)
#? dict()
overload_f1({'': ''})
#? str() dict()
overload_f1(lst)
#? str() dict()
overload_f1(list_alias)
#? str()
overload_f1(list_str)
#? str() dict()
overload_f1(list_int)

View File

@@ -99,6 +99,8 @@ def tuple(p, q, r):
"""
#? int()
p[0]
#? ['index']
p.index
#? int()
q[0]
#? str()
@@ -214,7 +216,7 @@ def union(p, q, r, s, t):
r
#? int() str() float() dict()
s
#? int()
#? int() None
t
def optional(p):
@@ -363,6 +365,17 @@ in_out1(str())
#?
in_out1()
def type_in_out1(x: typing.Type[TYPE_VARX]) -> TYPE_VARX: ...
#? int()
type_in_out1(int)
#? str()
type_in_out1(str)
#? float()
type_in_out1(float)
#?
type_in_out1()
def in_out2(x: TYPE_VAR_CONSTRAINTSX) -> TYPE_VAR_CONSTRAINTSX: ...
#? int()
@@ -377,6 +390,49 @@ in_out2()
#? float()
in_out2(1.0)
def type_in_out2(x: typing.Type[TYPE_VAR_CONSTRAINTSX]) -> TYPE_VAR_CONSTRAINTSX: ...
#? int()
type_in_out2(int)
#? str()
type_in_out2(str)
#? str() int()
type_in_out2()
# TODO this should actually be str() int(), because of the constraints.
#? float()
type_in_out2(float)
def ma(a: typing.Callable[[str], TYPE_VARX]) -> typing.Callable[[str], TYPE_VARX]:
return a
def mf(s: str) -> int:
return int(s)
#? int()
ma(mf)('2')
def xxx(x: typing.Iterable[TYPE_VARX]) -> typing.Tuple[str, TYPE_VARX]: ...
#? str()
xxx([0])[0]
#? int()
xxx([0])[1]
#?
xxx([0])[2]
def call_pls() -> typing.Callable[[TYPE_VARX], TYPE_VARX]: ...
#? int()
call_pls()(1)
def call2_pls() -> typing.Callable[[str, typing.Callable[[int], TYPE_VARX]], TYPE_VARX]: ...
#? float()
call2_pls('')(1, lambda x: 3.0)
def call3_pls() -> typing.Callable[[typing.Callable[[int], TYPE_VARX]], typing.List[TYPE_VARX]]: ...
def the_callable() -> float: ...
#? float()
call3_pls()(the_callable)[0]
# -------------------------
# TYPE_CHECKING
# -------------------------

138
test/completion/pytest.py Normal file
View File

@@ -0,0 +1,138 @@
# python > 2.7
import pytest
from pytest import fixture
@pytest.fixture(scope='module')
def my_fixture() -> str:
pass
@fixture
def my_simple_fixture():
return 1
@fixture
def my_yield_fixture():
yield 1
@fixture
class MyClassFixture():
pass
# -----------------
# goto/infer
# -----------------
#! 18 ['def my_conftest_fixture']
def test_x(my_conftest_fixture, my_fixture, my_not_existing_fixture, my_yield_fixture):
#? str()
my_fixture
#? int()
my_yield_fixture
#?
my_not_existing_fixture
#? float()
return my_conftest_fixture
#? 18 float()
def test_x(my_conftest_fixture, my_fixture):
pass
#! 18 ['param MyClassFixture']
def test_x(MyClassFixture):
#?
MyClassFixture
#? 15
def lala(my_fixture):
pass
@pytest.fixture
#? 15 str()
def lala(my_fixture):
pass
#! 15 ['param my_fixture']
def lala(my_fixture):
pass
@pytest.fixture
#! 15 ['def my_fixture']
def lala(my_fixture):
pass
# -----------------
# completion
# -----------------
#? 34 ['my_fixture']
def test_x(my_simple_fixture, my_fixture):
return
#? 34 ['my_fixture']
def test_x(my_simple_fixture, my_fixture):
return
#? ['my_fixture']
def test_x(my_simple_fixture, my_f
return
#? 18 ['my_simple_fixture']
def test_x(my_simple_fixture):
return
#? ['my_simple_fixture']
def test_x(my_simp
return
#? ['my_conftest_fixture']
def test_x(my_con
return
#? 18 ['my_conftest_fixture']
def test_x(my_conftest_fixture):
return
#? []
def lala(my_con
return
@pytest.fixture
#? ['my_conftest_fixture']
def lala(my_con
return
@pytest.fixture
#? 15 ['my_conftest_fixture']
def lala(my_con):
return
@pytest.fixture
@some_decorator
#? ['my_conftest_fixture']
def lala(my_con
return
@pytest.fixture
@some_decorator
#? 15 ['my_conftest_fixture']
def lala(my_con):
return
# -----------------
# pytest owned fixtures
# -----------------
#? ['monkeypatch']
def test_p(monkeyp
#! 15 ['def monkeypatch']
def test_p(monkeypatch):
#? ['setattr']
monkeypatch.setatt
#? ['capsysbinary']
def test_p(capsysbin
#? ['tmpdir', 'tmpdir_factory']
def test_p(tmpdi

View File

@@ -190,6 +190,10 @@ def huhu(db):
#? sqlite3.Connection()
db
with sqlite3.connect() as c:
#? sqlite3.Connection()
c
# -----------------
# hashlib
# -----------------
@@ -288,6 +292,55 @@ for part in qsplit:
#? str()
part
# -----------------
# staticmethod, classmethod params
# -----------------
class F():
def __init__(self):
self.my_variable = 3
@staticmethod
def my_func(param):
#? []
param.my_
#? ['upper']
param.uppe
#? str()
return param
@staticmethod
def my_func_without_call(param):
#? []
param.my_
#? []
param.uppe
#?
return param
@classmethod
def my_method_without_call(cls, param):
#?
cls.my_variable
#? ['my_method', 'my_method_without_call']
cls.my_meth
#?
return param
@classmethod
def my_method(cls, param):
#?
cls.my_variable
#? ['my_method', 'my_method_without_call']
cls.my_meth
#?
return param
#? str()
F.my_func('')
#? str()
F.my_method('')
# -----------------
# Unknown metaclass
# -----------------
@@ -329,3 +382,24 @@ X.attr_y.value
X().name
#? float()
X().attr_x.attr_y.value
# -----------------
# functools Python 3.8
# -----------------
# python >= 3.8
@functools.lru_cache
def x() -> int: ...
@functools.lru_cache()
def y() -> float: ...
@functools.lru_cache(8)
def z() -> str: ...
#? int()
x()
#? float()
y()
#? str()
z()

View File

@@ -1 +1,9 @@
in_stub_only: int
class Foo(Bar):
pass
class Bar:
pass

View File

@@ -1,7 +1,7 @@
from jedi import functions, inference, parsing
el = functions.completions()[0]
el = functions.complete()[0]
#? ['description']
el.description

View File

@@ -1,36 +1,36 @@
"""
Renaming tests. This means search for usages.
Renaming tests. This means search for references.
I always leave a little bit of space to add room for additions, because the
results always contain position informations.
"""
#< 4 (0,4), (3,0), (5,0), (17,0), (12,4), (14,5), (15,0)
def abc(): pass
#< 4 (0,4), (3,0), (5,0), (12,4), (14,5), (15,0), (17,0), (19,0)
def abcd(): pass
#< 0 (-3,4), (0,0), (2,0), (14,0), (9,4), (11,5), (12,0)
abc.d.a.bsaasd.abc.d
#< 0 (-3,4), (0,0), (2,0), (9,4), (11,5), (12,0), (14,0), (16,0)
abcd.d.a.bsaasd.abcd.d
abc
abcd
# unicode chars shouldn't be a problem.
x['smörbröd'].abc
x['smörbröd'].abcd
# With the new parser these statements are not recognized as stateents, because
# they are not valid Python.
if 1:
abc =
abcd =
else:
(abc) =
abc =
#< (-17,4), (-14,0), (-12,0), (0,0), (-2,0), (-3,5), (-5,4)
abc
(abcd) =
abcd =
#< (-17,4), (-14,0), (-12,0), (0,0), (2,0), (-2,0), (-3,5), (-5,4)
abcd
abc = 5
abcd = 5
Abc = 3
#< 6 (0,6), (2,4), (5,8), (17,0)
#< 6 (-3,0), (0,6), (2,4), (5,8), (17,0)
class Abc():
#< (-2,6), (0,4), (3,8), (15,0)
#< (-5,0), (-2,6), (0,4), (2,8), (3,8), (15,0)
Abc
def Abc(self):
@@ -63,13 +63,20 @@ def a(): pass
set_object_var = object()
set_object_var.var = 1
def func(a, b):
a = 12
#< 4 (0,4), (3,8)
c = a
if True:
#< 8 (-3,4), (0,8)
c = b
response = 5
#< 0 (0,0), (1,0), (2,0), (4,0)
#< 0 (-2,0), (0,0), (1,0), (2,0), (4,0)
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s.pdf' % id
response.write(pdf)
#< (-4,0), (-3,0), (-2,0), (0,0)
#< (-6,0), (-4,0), (-3,0), (-2,0), (0,0)
response
@@ -215,18 +222,18 @@ class TestProperty:
self.prop
@property
#< 13 (0,8), (4,5)
#< 13 (0,8), (4,5), (6,8), (11,13)
def rw_prop(self):
return self._rw_prop
#< 8 (-4,8), (0,5)
#< 8 (-4,8), (0,5), (2,8), (7,13)
@rw_prop.setter
#< 8 (0,8), (5,13)
#< 8 (-6,8), (-2,5), (0,8), (5,13)
def rw_prop(self, value):
self._rw_prop = value
def b(self):
#< 13 (-5,8), (0,13)
#< 13 (-11,8), (-7,5), (-5,8), (0,13)
self.rw_prop
# -----------------
@@ -287,9 +294,9 @@ x = 32
[x for x in x]
#< 0 (0,0), (2,1), (2,12)
x = 32
y = 32
#< 12 (-2,0), (0,1), (0,12)
[x for b in x]
[y for b in y]
#< 1 (0,1), (0,7)
@@ -297,13 +304,13 @@ x = 32
#< 7 (0,1), (0,7)
[x for x in something]
x = 3
z = 3
#< 1 (0,1), (0,10)
{x:1 for x in something}
{z:1 for z in something}
#< 10 (0,1), (0,10)
{x:1 for x in something}
{z:1 for z in something}
def x():
def whatever_func():
zzz = 3
if UNDEFINED:
zzz = 5
@@ -314,3 +321,31 @@ def x():
#< (0, 8), (1, 4), (-3, 12), (-6, 8), (-8, 4)
zzz
zzz
# -----------------
# global
# -----------------
def global_usage1():
#< (0, 4), (4, 11), (6, 4), (9, 8), (12, 4)
my_global
def global_definition():
#< (-4, 4), (0, 11), (2, 4), (5, 8), (8, 4)
global my_global
#< 4 (-6, 4), (-2, 11), (0, 4), (3, 8), (6, 4)
my_global = 3
if WHATEVER:
#< 8 (-9, 4), (-5, 11), (-3, 4), (0, 8), (3, 4)
my_global = 4
def global_usage2()
my_global
def not_global(my_global):
my_global
class DefinitelyNotGlobal:
def my_global(self):
def my_global(self):
pass