diff --git a/evaluate.py b/evaluate.py index 3f084a8d..190bb780 100644 --- a/evaluate.py +++ b/evaluate.py @@ -79,16 +79,15 @@ class Executable(object): class Instance(Executable): """ 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): - for sub in self.base.subscopes: - if isinstance(sub, parsing.Function) \ - and sub.name.get_code() == '__init__': - self.set_param_cb(InstanceElement(self, Function.create(sub))) + @memoize_default() + def get_init_execution(self, func): + if isinstance(func, parsing.Function): + #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): """ @@ -113,11 +112,14 @@ class Instance(Executable): names = [] # this loop adds the names of the self object, copies them and removes # the self. - for s in self.base.subscopes: + for sub in self.base.subscopes: # 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: - 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. # It is also important, that they have a len() of 2, # because otherwise, they are just something else @@ -461,7 +463,7 @@ class Execution(Executable): return iter(PushBackIterator(iterate())) def get_set_vars(self): - raise NotImplementedError("This should never be called") + return self.get_defined_names() def get_defined_names(self): """ diff --git a/test/completion/classes.py b/test/completion/classes.py index b44e4a09..43ad6125 100644 --- a/test/completion/classes.py +++ b/test/completion/classes.py @@ -55,10 +55,8 @@ TestClass().ret(1).real inst.ret(1).real myclass = TestClass(1, '') -#? ['real'] -myclass.get_first().real -#? [] -myclass.get_first().upper +#? int() +myclass.get_first() #? [] myclass.get_first.real @@ -67,20 +65,16 @@ myclass.get_first.real TestClass(1,1,1).var_inst.real # too few params -#? ['real'] -TestClass(1).first.real +#? int() +TestClass(1).first #? [] -TestClass(1).second.real +TestClass(1).second. # complicated variable settings in class -#? ['upper'] -myclass.second.upper -#? [] -myclass.second.real -#? ['upper'] -myclass.second_new.upper -#? [] -myclass.second_new.real +#? str() +myclass.second +#? str() +myclass.second_new # multiple classes / ordering ints = TestClass(1, 1.0) diff --git a/test/completion/functions.py b/test/completion/functions.py index 86c52168..7d64a11e 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -74,13 +74,11 @@ def func(a=1, b=''): return a, b exe = func(b=list, a=tuple) -#? [] -exe[0].real -#? ['index'] -exe[0].index +#? tuple() +exe[0] -#? ['append'] -exe[1].append +#? list() +exe[1] # ----------------- # default arguments @@ -115,49 +113,35 @@ def args_func(*args): return args exe = args_func(1, "") -#? ['real'] -exe[0].real -#? [] -exe[0].upper +#? int() +exe[0] -#? [] -exe[1].real -#? ['upper'] -exe[1].upper +#? str() +exe[1] -lis = [1,""] -exe2 = args_func(lis)[0] +_list = [1,""] +exe2 = args_func(_list)[0] -#? [] -exe2[1].real -#? ['upper'] -exe2[1].upper +#? str() +exe2[1] exe3 = args_func([1,""])[0] -#? [] -exe3[1].real -#? ['upper'] -exe3[1].upper +#? str() +exe3[1] def args_func(arg1, *args): return arg1, args exe = args_func(1, "", list) -#? ['real'] -exe[0].real -#? [] -exe[0].upper +#? int() +exe[0] -#? [] -exe[1].real -#? ['index'] +#? tuple() exe[1].index -#? [] -exe[1][1].upper -#? ['append'] -exe[1][1].append +#? list() +exe[1][1] # ----------------- # ** kwargs @@ -188,10 +172,8 @@ exe[2].index exe[2][0].upper #? ['items'] exe[3].items -#? ['union'] -exe[3]['c'].union -#? [] -exe[3]['c'].upper +#? set() +exe[3]['c'] # ----------------- # decorators @@ -208,15 +190,11 @@ def decorated(a,b): exe = decorated(set, '') -#? [] -exe[0].union -#? ['union'] -exe[1].union +#? set +exe[1] -#? ['real'] -exe[0].real -#? [] -exe[1].real +#? int() +exe[0] # more complicated with args/kwargs def dec(func): @@ -237,18 +215,14 @@ exe[1].real #? ['union'] exe[2].union -#? [] -exe[4]['d'].union -#? ['upper'] -exe[4]['d'].upper +#? str() +exe[4]['d'] exe = fu(list, set, 3, '', d='') -#? ['upper'] -exe[3][0].upper -#? [] -exe[3][0].real +#? str() +exe[3][0] # -----------------