mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
class inheritance (only instances)
This commit is contained in:
10
evaluate.py
10
evaluate.py
@@ -35,7 +35,7 @@ def get_defined_names_for_position(obj, position):
|
|||||||
return names
|
return names
|
||||||
names_new = []
|
names_new = []
|
||||||
for n in names:
|
for n in names:
|
||||||
if (n.line_nr, n.indent) <= position:
|
if (n.line_nr, n.indent) < position:
|
||||||
names_new.append(n)
|
names_new.append(n)
|
||||||
return names_new
|
return names_new
|
||||||
|
|
||||||
@@ -167,6 +167,14 @@ class Instance(Executable):
|
|||||||
if isinstance(var.parent, (parsing.Function)):
|
if isinstance(var.parent, (parsing.Function)):
|
||||||
var = InstanceElement(self, var)
|
var = InstanceElement(self, var)
|
||||||
names.append(var)
|
names.append(var)
|
||||||
|
|
||||||
|
# check super classes:
|
||||||
|
for s in self.base.supers:
|
||||||
|
for cls in follow_statement(s):
|
||||||
|
# get the inherited names
|
||||||
|
for i in Instance(cls).get_defined_names():
|
||||||
|
if not i.in_iterable(names):
|
||||||
|
names.append(i)
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def parent(self):
|
def parent(self):
|
||||||
|
|||||||
2
ftest.py
2
ftest.py
@@ -15,7 +15,7 @@ path = os.path.join(os.getcwd(), f_name)
|
|||||||
f = open(path)
|
f = open(path)
|
||||||
code = f.read()
|
code = f.read()
|
||||||
for i in range(1):
|
for i in range(1):
|
||||||
completions = functions.complete(code, 160, 200, path)
|
completions = functions.complete(code, 180, 200, path)
|
||||||
#completions = functions.complete(code, 42, 200, path)
|
#completions = functions.complete(code, 42, 200, path)
|
||||||
|
|
||||||
print '\n', ', '.join(sorted(str(c) for c in completions))
|
print '\n', ', '.join(sorted(str(c) for c in completions))
|
||||||
|
|||||||
29
parsetest.py
29
parsetest.py
@@ -154,8 +154,27 @@ flow_test.; a12, (b12, c12) = (1,(list, "")); b12.
|
|||||||
def globalfunc():
|
def globalfunc():
|
||||||
global globalvar, globalvar2
|
global globalvar, globalvar2
|
||||||
globalvar = 3
|
globalvar = 3
|
||||||
a8 = 3
|
a = 3; b = ""
|
||||||
a8 = tuple
|
b,a=a,b
|
||||||
# completion:
|
a.
|
||||||
a8.
|
|
||||||
a8=list
|
class SuperClass(object):
|
||||||
|
super_class = 3
|
||||||
|
def __init__(self):
|
||||||
|
self.super_var = ''
|
||||||
|
def super_method(self)
|
||||||
|
self.super_var2 = list
|
||||||
|
class Mixin(SuperClass):
|
||||||
|
def super_method(self):
|
||||||
|
return int
|
||||||
|
class SubClass(Mixin, SuperClass):
|
||||||
|
sub_class = 3
|
||||||
|
def __init__(self):
|
||||||
|
self.sub_var = ''
|
||||||
|
def sub_method(self):
|
||||||
|
self.sub_var2 = list
|
||||||
|
return tuple
|
||||||
|
instance = SubClass()
|
||||||
|
|
||||||
|
|
||||||
|
instance.
|
||||||
|
|||||||
@@ -884,6 +884,13 @@ class Name(Simple):
|
|||||||
""" Returns the names in a full string format """
|
""" Returns the names in a full string format """
|
||||||
return ".".join(self.names)
|
return ".".join(self.names)
|
||||||
|
|
||||||
|
def in_iterable(self, iterable):
|
||||||
|
for i in iterable:
|
||||||
|
if i.names == self.names:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.get_code()
|
return self.get_code()
|
||||||
|
|
||||||
|
|||||||
@@ -92,3 +92,42 @@ strs.second.upper
|
|||||||
|
|
||||||
#? ['var_class']
|
#? ['var_class']
|
||||||
TestClass.var_class.var_class.var_class.var_class
|
TestClass.var_class.var_class.var_class.var_class
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# inheritance
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class SuperClass(object):
|
||||||
|
class_super = 3
|
||||||
|
def __init__(self):
|
||||||
|
self.var_super = ''
|
||||||
|
def method_super(self):
|
||||||
|
self.var2_super = list
|
||||||
|
|
||||||
|
class Mixin(SuperClass):
|
||||||
|
def method_super(self):
|
||||||
|
return int
|
||||||
|
|
||||||
|
class SubClass(SuperClass):
|
||||||
|
class_sub = 3
|
||||||
|
def __init__(self):
|
||||||
|
self.var_sub = ''
|
||||||
|
def method_sub(self):
|
||||||
|
self.var_sub = list
|
||||||
|
return tuple
|
||||||
|
|
||||||
|
instance = SubClass()
|
||||||
|
|
||||||
|
#? ['method_sub', 'method_super']
|
||||||
|
instance.method_
|
||||||
|
#? ['var2_super', 'var_sub', 'var_super']
|
||||||
|
instance.var
|
||||||
|
#? ['class_sub', 'class_super']
|
||||||
|
instance.class_
|
||||||
|
|
||||||
|
#? ['method_sub', 'method_super']
|
||||||
|
SubClass.method_
|
||||||
|
#? []
|
||||||
|
SubClass.var
|
||||||
|
#? ['class_sub', 'class_super']
|
||||||
|
SubClass.class_
|
||||||
|
|||||||
@@ -13,11 +13,24 @@ a.append
|
|||||||
|
|
||||||
a = list
|
a = list
|
||||||
|
|
||||||
b ="";b=1
|
b = 1; b = ""
|
||||||
|
#? ['upper']
|
||||||
|
b.upper
|
||||||
|
#? []
|
||||||
|
b.real
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
temp = b;
|
||||||
|
b = a
|
||||||
|
a = temp
|
||||||
#? ['real']
|
#? ['real']
|
||||||
b.real
|
b.real
|
||||||
#? []
|
#? []
|
||||||
b.upper
|
b.upper
|
||||||
|
#? []
|
||||||
|
a.real
|
||||||
|
#? ['upper']
|
||||||
|
a.upper
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# tuples exchanges
|
# tuples exchanges
|
||||||
@@ -42,6 +55,15 @@ a.real
|
|||||||
#? ['upper']
|
#? ['upper']
|
||||||
a.upper
|
a.upper
|
||||||
|
|
||||||
|
b, a = a, b
|
||||||
|
#? ['real']
|
||||||
|
a.real
|
||||||
|
#? []
|
||||||
|
a.upper
|
||||||
|
#? []
|
||||||
|
b.real
|
||||||
|
#? ['upper']
|
||||||
|
b.upper
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# function stuff
|
# function stuff
|
||||||
|
|||||||
Reference in New Issue
Block a user