mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
move descriptors out of classes into their own file
This commit is contained in:
@@ -248,192 +248,6 @@ class A():
|
|||||||
#? list()
|
#? list()
|
||||||
A().b()
|
A().b()
|
||||||
|
|
||||||
# -----------------
|
|
||||||
# descriptors
|
|
||||||
# -----------------
|
|
||||||
class RevealAccess(object):
|
|
||||||
"""
|
|
||||||
A data descriptor that sets and returns values
|
|
||||||
normally and prints a message logging their access.
|
|
||||||
"""
|
|
||||||
def __init__(self, initval=None, name='var'):
|
|
||||||
self.val = initval
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
def __get__(self, obj, objtype):
|
|
||||||
print('Retrieving', self.name)
|
|
||||||
return self.val
|
|
||||||
|
|
||||||
def __set__(self, obj, val):
|
|
||||||
print('Updating', self.name)
|
|
||||||
self.val = val
|
|
||||||
|
|
||||||
def just_a_method(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class C(object):
|
|
||||||
x = RevealAccess(10, 'var "x"')
|
|
||||||
#? RevealAccess()
|
|
||||||
x
|
|
||||||
#? ['just_a_method']
|
|
||||||
x.just_a_method
|
|
||||||
y = 5.0
|
|
||||||
def __init__(self):
|
|
||||||
#? int()
|
|
||||||
self.x
|
|
||||||
|
|
||||||
#? []
|
|
||||||
self.just_a_method
|
|
||||||
#? []
|
|
||||||
C.just_a_method
|
|
||||||
|
|
||||||
m = C()
|
|
||||||
#? int()
|
|
||||||
m.x
|
|
||||||
#? float()
|
|
||||||
m.y
|
|
||||||
#? int()
|
|
||||||
C.x
|
|
||||||
|
|
||||||
#? []
|
|
||||||
m.just_a_method
|
|
||||||
#? []
|
|
||||||
C.just_a_method
|
|
||||||
|
|
||||||
# -----------------
|
|
||||||
# properties
|
|
||||||
# -----------------
|
|
||||||
class B():
|
|
||||||
@property
|
|
||||||
def r(self):
|
|
||||||
return 1
|
|
||||||
@r.setter
|
|
||||||
def r(self, value):
|
|
||||||
return ''
|
|
||||||
def t(self):
|
|
||||||
return ''
|
|
||||||
p = property(t)
|
|
||||||
|
|
||||||
#? []
|
|
||||||
B().r()
|
|
||||||
#? int()
|
|
||||||
B().r
|
|
||||||
|
|
||||||
#? str()
|
|
||||||
B().p
|
|
||||||
#? []
|
|
||||||
B().p()
|
|
||||||
|
|
||||||
class PropClass():
|
|
||||||
def __init__(self, a):
|
|
||||||
self.a = a
|
|
||||||
@property
|
|
||||||
def ret(self):
|
|
||||||
return self.a
|
|
||||||
|
|
||||||
@ret.setter
|
|
||||||
def ret(self, value):
|
|
||||||
return 1.0
|
|
||||||
|
|
||||||
def ret2(self):
|
|
||||||
return self.a
|
|
||||||
ret2 = property(ret2)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def nested(self):
|
|
||||||
""" causes recusions in properties, should work """
|
|
||||||
return self.ret
|
|
||||||
|
|
||||||
@property
|
|
||||||
def nested2(self):
|
|
||||||
""" causes recusions in properties, should not work """
|
|
||||||
return self.nested2
|
|
||||||
|
|
||||||
@property
|
|
||||||
def join1(self):
|
|
||||||
""" mutual recusion """
|
|
||||||
return self.join2
|
|
||||||
|
|
||||||
@property
|
|
||||||
def join2(self):
|
|
||||||
""" mutual recusion """
|
|
||||||
return self.join1
|
|
||||||
|
|
||||||
#? str()
|
|
||||||
PropClass("").ret
|
|
||||||
#? []
|
|
||||||
PropClass().ret.
|
|
||||||
|
|
||||||
#? str()
|
|
||||||
PropClass("").ret2
|
|
||||||
#?
|
|
||||||
PropClass().ret2
|
|
||||||
|
|
||||||
#? int()
|
|
||||||
PropClass(1).nested
|
|
||||||
#? []
|
|
||||||
PropClass().nested.
|
|
||||||
|
|
||||||
#?
|
|
||||||
PropClass(1).nested2
|
|
||||||
#? []
|
|
||||||
PropClass().nested2.
|
|
||||||
|
|
||||||
#?
|
|
||||||
PropClass(1).join1
|
|
||||||
# -----------------
|
|
||||||
# staticmethod/classmethod
|
|
||||||
# -----------------
|
|
||||||
|
|
||||||
class E(object):
|
|
||||||
a = ''
|
|
||||||
def __init__(self, a):
|
|
||||||
self.a = a
|
|
||||||
|
|
||||||
def f(x):
|
|
||||||
return x
|
|
||||||
f = staticmethod(f)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def g(x):
|
|
||||||
return x
|
|
||||||
|
|
||||||
def s(cls, x):
|
|
||||||
return x
|
|
||||||
s = classmethod(s)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def t(cls, x):
|
|
||||||
return x
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def u(cls, x):
|
|
||||||
return cls.a
|
|
||||||
|
|
||||||
e = E(1)
|
|
||||||
#? int()
|
|
||||||
e.f(1)
|
|
||||||
#? int()
|
|
||||||
E.f(1)
|
|
||||||
#? int()
|
|
||||||
e.g(1)
|
|
||||||
#? int()
|
|
||||||
E.g(1)
|
|
||||||
|
|
||||||
#? int()
|
|
||||||
e.s(1)
|
|
||||||
#? int()
|
|
||||||
E.s(1)
|
|
||||||
#? int()
|
|
||||||
e.t(1)
|
|
||||||
#? int()
|
|
||||||
E.t(1)
|
|
||||||
|
|
||||||
#? str()
|
|
||||||
e.u(1)
|
|
||||||
#? str()
|
|
||||||
E.u(1)
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# recursions
|
# recursions
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
182
test/completion/descriptors.py
Normal file
182
test/completion/descriptors.py
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
class RevealAccess(object):
|
||||||
|
"""
|
||||||
|
A data descriptor that sets and returns values
|
||||||
|
normally and prints a message logging their access.
|
||||||
|
"""
|
||||||
|
def __init__(self, initval=None, name='var'):
|
||||||
|
self.val = initval
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def __get__(self, obj, objtype):
|
||||||
|
print('Retrieving', self.name)
|
||||||
|
return self.val
|
||||||
|
|
||||||
|
def __set__(self, obj, val):
|
||||||
|
print('Updating', self.name)
|
||||||
|
self.val = val
|
||||||
|
|
||||||
|
def just_a_method(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class C(object):
|
||||||
|
x = RevealAccess(10, 'var "x"')
|
||||||
|
#? RevealAccess()
|
||||||
|
x
|
||||||
|
#? ['just_a_method']
|
||||||
|
x.just_a_method
|
||||||
|
y = 5.0
|
||||||
|
def __init__(self):
|
||||||
|
#? int()
|
||||||
|
self.x
|
||||||
|
|
||||||
|
#? []
|
||||||
|
self.just_a_method
|
||||||
|
#? []
|
||||||
|
C.just_a_method
|
||||||
|
|
||||||
|
m = C()
|
||||||
|
#? int()
|
||||||
|
m.x
|
||||||
|
#? float()
|
||||||
|
m.y
|
||||||
|
#? int()
|
||||||
|
C.x
|
||||||
|
|
||||||
|
#? []
|
||||||
|
m.just_a_method
|
||||||
|
#? []
|
||||||
|
C.just_a_method
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# properties
|
||||||
|
# -----------------
|
||||||
|
class B():
|
||||||
|
@property
|
||||||
|
def r(self):
|
||||||
|
return 1
|
||||||
|
@r.setter
|
||||||
|
def r(self, value):
|
||||||
|
return ''
|
||||||
|
def t(self):
|
||||||
|
return ''
|
||||||
|
p = property(t)
|
||||||
|
|
||||||
|
#? []
|
||||||
|
B().r()
|
||||||
|
#? int()
|
||||||
|
B().r
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
B().p
|
||||||
|
#? []
|
||||||
|
B().p()
|
||||||
|
|
||||||
|
class PropClass():
|
||||||
|
def __init__(self, a):
|
||||||
|
self.a = a
|
||||||
|
@property
|
||||||
|
def ret(self):
|
||||||
|
return self.a
|
||||||
|
|
||||||
|
@ret.setter
|
||||||
|
def ret(self, value):
|
||||||
|
return 1.0
|
||||||
|
|
||||||
|
def ret2(self):
|
||||||
|
return self.a
|
||||||
|
ret2 = property(ret2)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nested(self):
|
||||||
|
""" causes recusions in properties, should work """
|
||||||
|
return self.ret
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nested2(self):
|
||||||
|
""" causes recusions in properties, should not work """
|
||||||
|
return self.nested2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def join1(self):
|
||||||
|
""" mutual recusion """
|
||||||
|
return self.join2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def join2(self):
|
||||||
|
""" mutual recusion """
|
||||||
|
return self.join1
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
PropClass("").ret
|
||||||
|
#? []
|
||||||
|
PropClass().ret.
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
PropClass("").ret2
|
||||||
|
#?
|
||||||
|
PropClass().ret2
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
PropClass(1).nested
|
||||||
|
#? []
|
||||||
|
PropClass().nested.
|
||||||
|
|
||||||
|
#?
|
||||||
|
PropClass(1).nested2
|
||||||
|
#? []
|
||||||
|
PropClass().nested2.
|
||||||
|
|
||||||
|
#?
|
||||||
|
PropClass(1).join1
|
||||||
|
# -----------------
|
||||||
|
# staticmethod/classmethod
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class E(object):
|
||||||
|
a = ''
|
||||||
|
def __init__(self, a):
|
||||||
|
self.a = a
|
||||||
|
|
||||||
|
def f(x):
|
||||||
|
return x
|
||||||
|
f = staticmethod(f)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def g(x):
|
||||||
|
return x
|
||||||
|
|
||||||
|
def s(cls, x):
|
||||||
|
return x
|
||||||
|
s = classmethod(s)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def t(cls, x):
|
||||||
|
return x
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def u(cls, x):
|
||||||
|
return cls.a
|
||||||
|
|
||||||
|
e = E(1)
|
||||||
|
#? int()
|
||||||
|
e.f(1)
|
||||||
|
#? int()
|
||||||
|
E.f(1)
|
||||||
|
#? int()
|
||||||
|
e.g(1)
|
||||||
|
#? int()
|
||||||
|
E.g(1)
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
e.s(1)
|
||||||
|
#? int()
|
||||||
|
E.s(1)
|
||||||
|
#? int()
|
||||||
|
e.t(1)
|
||||||
|
#? int()
|
||||||
|
E.t(1)
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
e.u(1)
|
||||||
|
#? str()
|
||||||
|
E.u(1)
|
||||||
Reference in New Issue
Block a user