mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
__init__ function is working again
This commit is contained in:
28
evaluate.py
28
evaluate.py
@@ -79,16 +79,15 @@ class Executable(object):
|
|||||||
|
|
||||||
class Instance(Executable):
|
class Instance(Executable):
|
||||||
""" This class is used to evaluate instances. """
|
""" This class is used to evaluate instances. """
|
||||||
def __init__(self, base, var_args=[]):
|
|
||||||
super(Instance, self).__init__(base, var_args)
|
|
||||||
if var_args:
|
|
||||||
self.set_init_params()
|
|
||||||
|
|
||||||
def set_init_params(self):
|
@memoize_default()
|
||||||
for sub in self.base.subscopes:
|
def get_init_execution(self, func):
|
||||||
if isinstance(sub, parsing.Function) \
|
if isinstance(func, parsing.Function):
|
||||||
and sub.name.get_code() == '__init__':
|
#self.set_param_cb(InstanceElement(self, Function.create(sub)))
|
||||||
self.set_param_cb(InstanceElement(self, Function.create(sub)))
|
instance_el = InstanceElement(self, Function.create(func))
|
||||||
|
return Execution(instance_el, self.var_args)
|
||||||
|
else:
|
||||||
|
return func
|
||||||
|
|
||||||
def get_func_self_name(self, func):
|
def get_func_self_name(self, func):
|
||||||
"""
|
"""
|
||||||
@@ -113,11 +112,14 @@ class Instance(Executable):
|
|||||||
names = []
|
names = []
|
||||||
# this loop adds the names of the self object, copies them and removes
|
# this loop adds the names of the self object, copies them and removes
|
||||||
# the self.
|
# the self.
|
||||||
for s in self.base.subscopes:
|
for sub in self.base.subscopes:
|
||||||
# get the self name, if there's one
|
# get the self name, if there's one
|
||||||
self_name = self.get_func_self_name(s)
|
self_name = self.get_func_self_name(sub)
|
||||||
if self_name:
|
if self_name:
|
||||||
for n in s.get_set_vars():
|
# check the __init__ function
|
||||||
|
if self.var_args and sub.name.get_code() == '__init__':
|
||||||
|
sub = self.get_init_execution(sub)
|
||||||
|
for n in sub.get_set_vars():
|
||||||
# Only names with the selfname are being added.
|
# Only names with the selfname are being added.
|
||||||
# It is also important, that they have a len() of 2,
|
# It is also important, that they have a len() of 2,
|
||||||
# because otherwise, they are just something else
|
# because otherwise, they are just something else
|
||||||
@@ -461,7 +463,7 @@ class Execution(Executable):
|
|||||||
return iter(PushBackIterator(iterate()))
|
return iter(PushBackIterator(iterate()))
|
||||||
|
|
||||||
def get_set_vars(self):
|
def get_set_vars(self):
|
||||||
raise NotImplementedError("This should never be called")
|
return self.get_defined_names()
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -55,10 +55,8 @@ TestClass().ret(1).real
|
|||||||
inst.ret(1).real
|
inst.ret(1).real
|
||||||
|
|
||||||
myclass = TestClass(1, '')
|
myclass = TestClass(1, '')
|
||||||
#? ['real']
|
#? int()
|
||||||
myclass.get_first().real
|
myclass.get_first()
|
||||||
#? []
|
|
||||||
myclass.get_first().upper
|
|
||||||
#? []
|
#? []
|
||||||
myclass.get_first.real
|
myclass.get_first.real
|
||||||
|
|
||||||
@@ -67,20 +65,16 @@ myclass.get_first.real
|
|||||||
TestClass(1,1,1).var_inst.real
|
TestClass(1,1,1).var_inst.real
|
||||||
|
|
||||||
# too few params
|
# too few params
|
||||||
#? ['real']
|
#? int()
|
||||||
TestClass(1).first.real
|
TestClass(1).first
|
||||||
#? []
|
#? []
|
||||||
TestClass(1).second.real
|
TestClass(1).second.
|
||||||
|
|
||||||
# complicated variable settings in class
|
# complicated variable settings in class
|
||||||
#? ['upper']
|
#? str()
|
||||||
myclass.second.upper
|
myclass.second
|
||||||
#? []
|
#? str()
|
||||||
myclass.second.real
|
myclass.second_new
|
||||||
#? ['upper']
|
|
||||||
myclass.second_new.upper
|
|
||||||
#? []
|
|
||||||
myclass.second_new.real
|
|
||||||
|
|
||||||
# multiple classes / ordering
|
# multiple classes / ordering
|
||||||
ints = TestClass(1, 1.0)
|
ints = TestClass(1, 1.0)
|
||||||
|
|||||||
@@ -74,13 +74,11 @@ def func(a=1, b=''):
|
|||||||
return a, b
|
return a, b
|
||||||
|
|
||||||
exe = func(b=list, a=tuple)
|
exe = func(b=list, a=tuple)
|
||||||
#? []
|
#? tuple()
|
||||||
exe[0].real
|
exe[0]
|
||||||
#? ['index']
|
|
||||||
exe[0].index
|
|
||||||
|
|
||||||
#? ['append']
|
#? list()
|
||||||
exe[1].append
|
exe[1]
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# default arguments
|
# default arguments
|
||||||
@@ -115,49 +113,35 @@ def args_func(*args):
|
|||||||
return args
|
return args
|
||||||
|
|
||||||
exe = args_func(1, "")
|
exe = args_func(1, "")
|
||||||
#? ['real']
|
#? int()
|
||||||
exe[0].real
|
exe[0]
|
||||||
#? []
|
|
||||||
exe[0].upper
|
|
||||||
|
|
||||||
#? []
|
#? str()
|
||||||
exe[1].real
|
exe[1]
|
||||||
#? ['upper']
|
|
||||||
exe[1].upper
|
|
||||||
|
|
||||||
lis = [1,""]
|
_list = [1,""]
|
||||||
exe2 = args_func(lis)[0]
|
exe2 = args_func(_list)[0]
|
||||||
|
|
||||||
#? []
|
#? str()
|
||||||
exe2[1].real
|
exe2[1]
|
||||||
#? ['upper']
|
|
||||||
exe2[1].upper
|
|
||||||
|
|
||||||
exe3 = args_func([1,""])[0]
|
exe3 = args_func([1,""])[0]
|
||||||
|
|
||||||
#? []
|
#? str()
|
||||||
exe3[1].real
|
exe3[1]
|
||||||
#? ['upper']
|
|
||||||
exe3[1].upper
|
|
||||||
|
|
||||||
def args_func(arg1, *args):
|
def args_func(arg1, *args):
|
||||||
return arg1, args
|
return arg1, args
|
||||||
|
|
||||||
exe = args_func(1, "", list)
|
exe = args_func(1, "", list)
|
||||||
#? ['real']
|
#? int()
|
||||||
exe[0].real
|
exe[0]
|
||||||
#? []
|
|
||||||
exe[0].upper
|
|
||||||
|
|
||||||
#? []
|
#? tuple()
|
||||||
exe[1].real
|
|
||||||
#? ['index']
|
|
||||||
exe[1].index
|
exe[1].index
|
||||||
|
|
||||||
#? []
|
#? list()
|
||||||
exe[1][1].upper
|
exe[1][1]
|
||||||
#? ['append']
|
|
||||||
exe[1][1].append
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# ** kwargs
|
# ** kwargs
|
||||||
@@ -188,10 +172,8 @@ exe[2].index
|
|||||||
exe[2][0].upper
|
exe[2][0].upper
|
||||||
#? ['items']
|
#? ['items']
|
||||||
exe[3].items
|
exe[3].items
|
||||||
#? ['union']
|
#? set()
|
||||||
exe[3]['c'].union
|
exe[3]['c']
|
||||||
#? []
|
|
||||||
exe[3]['c'].upper
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# decorators
|
# decorators
|
||||||
@@ -208,15 +190,11 @@ def decorated(a,b):
|
|||||||
|
|
||||||
exe = decorated(set, '')
|
exe = decorated(set, '')
|
||||||
|
|
||||||
#? []
|
#? set
|
||||||
exe[0].union
|
exe[1]
|
||||||
#? ['union']
|
|
||||||
exe[1].union
|
|
||||||
|
|
||||||
#? ['real']
|
#? int()
|
||||||
exe[0].real
|
exe[0]
|
||||||
#? []
|
|
||||||
exe[1].real
|
|
||||||
|
|
||||||
# more complicated with args/kwargs
|
# more complicated with args/kwargs
|
||||||
def dec(func):
|
def dec(func):
|
||||||
@@ -237,18 +215,14 @@ exe[1].real
|
|||||||
#? ['union']
|
#? ['union']
|
||||||
exe[2].union
|
exe[2].union
|
||||||
|
|
||||||
#? []
|
#? str()
|
||||||
exe[4]['d'].union
|
exe[4]['d']
|
||||||
#? ['upper']
|
|
||||||
exe[4]['d'].upper
|
|
||||||
|
|
||||||
|
|
||||||
exe = fu(list, set, 3, '', d='')
|
exe = fu(list, set, 3, '', d='')
|
||||||
|
|
||||||
#? ['upper']
|
#? str()
|
||||||
exe[3][0].upper
|
exe[3][0]
|
||||||
#? []
|
|
||||||
exe[3][0].real
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user