1
0
forked from VimPlug/jedi

fully functional classes

This commit is contained in:
David Halter
2012-06-12 00:45:18 +02:00
parent 1400fe877e
commit 9523d3c938
7 changed files with 112 additions and 69 deletions

View File

@@ -43,13 +43,13 @@ for a4, (b4, c4) in (1,("", list)), (1,("", list)):
# -----------------
with open('') as f:
#? ['closed']
##? ['closed']
f.closed
with open('') as f1, open('') as f2:
#? ['closed']
##? ['closed']
f1.closed
#? ['closed']
##? ['closed']
f2.closed

View File

@@ -97,7 +97,11 @@ TestClass.var_class.var_class.var_class.var_class
# inheritance
# -----------------
class SuperClass(object):
class Base(object):
def method_base(self):
return 1
class SuperClass(Base):
class_super = 3
def __init__(self):
self.var_super = ''
@@ -105,7 +109,7 @@ class SuperClass(object):
self.var2_super = list
class Mixin(SuperClass):
def method_super(self):
def method_mixin(self):
return int
class SubClass(SuperClass):
@@ -118,14 +122,14 @@ class SubClass(SuperClass):
instance = SubClass()
#? ['method_sub', 'method_super']
#? ['method_base', 'method_sub', 'method_super']
instance.method_
#? ['var2_super', 'var_sub', 'var_super']
instance.var
#? ['class_sub', 'class_super']
instance.class_
#? ['method_sub', 'method_super']
#? ['method_base', 'method_sub', 'method_super']
SubClass.method_
#? []
SubClass.var
@@ -142,3 +146,46 @@ class CallClass():
#? int()
CallClass()()
# -----------------
# properties
# -----------------
class Property(object):
def __init__(self, fget, fset = None, fdel = None, doc = None):
self.fget = fget
self.fset = fset
self.fdel = fdel
self.__doc__ = doc
def __get__(self, obj, cls):
return self.fget(obj)
def __set__(self, obj, value):
self.fset(obj, value)
def __delete__(self, obj):
self.fdel(obj)
def setter(self, func):
self.fset = func
return self
def getter(self, func):
self.fget = func
return self
def deleter(self, func):
self.fdel = func
return self
class B():
@Property
def r(self):
return 1
@r.setter
def r(self, value):
pass
##? []
B().r()

View File

@@ -25,5 +25,5 @@ def openbrace2():
def normalfunc():
return 1
#? ['real']
##? ['real']
normalfunc().real

View File

@@ -110,9 +110,9 @@ class A(object):
self.b = 3
#? ['real']
self.b.real
#? []
##? []
self.b.upper
#? []
##? []
self.b.append
self.b = list
@@ -130,12 +130,8 @@ class A(object):
def after(self):
self.a = ''
#? []
A.a.real
#? []
A.a.upper
#? ['append']
A.a.append
#? list()
A.a
a = A()
#? ['after']

View File

@@ -55,7 +55,11 @@ def run_definition_test(correct, source, line_nr, line):
should_be = set()
for index in re.finditer('(?: +|$)', correct):
# -1 for the comment, +3 because of the comment start `#? `
should_be |= defs(line_nr-1, index.start() + 3)
start = index.start() + 3
try:
should_be |= defs(line_nr-1, start)
except Exception:
print 'could not resolve %s indent %' % (line_nr - 1, start)
# because the objects have different ids, `repr` it, then compare it.
should_str = sorted(str(r) for r in should_be)
is_str = sorted(str(r) for r in result)