functions fully working with default arguments/generators/decorators, but without recursion

This commit is contained in:
David Halter
2012-05-22 10:34:27 +02:00
parent da7ef3ba4b
commit 3c882dea44
3 changed files with 23 additions and 11 deletions

View File

@@ -352,6 +352,7 @@ class Execution(Executable):
for param in self.base.params[start_offset:]:
# The value and key can both be null. There, the defaults apply.
# args / kwargs will just be empty arrays / dicts, respectively.
keys_only = False
key, value = next(var_arg_iterator, (None, None))
while key:
try:
@@ -362,10 +363,12 @@ class Execution(Executable):
result.append(gen_param_name_copy(key_param,
values=[value]))
key, value = next(var_arg_iterator, (None, None))
keys_only = True
#debug.warning('Too many arguments given.', value)
assignment = param.get_assignment_calls().values[0]
assignments = param.get_assignment_calls().values
assignment = assignments[0]
keys = []
values = []
array_type = None
@@ -389,7 +392,14 @@ class Execution(Executable):
# normal param
if value:
values = [value]
else:
# just give it the default values (if there's something
# there)
values = assignments
# just ignore all the params that are without a key, after one
# keyword argument was set.
if not keys_only or assignment[0] == '**':
result.append(gen_param_name_copy(param, keys=keys, values=values,
array_type=array_type))
return result

View File

@@ -78,6 +78,7 @@ class Definition(object):
def get_module(self):
par = self.scope
while True:
# TODO what to do with `evaluate.Array` ?
if par.parent is not None:
par = par.parent
else:

View File

@@ -63,7 +63,7 @@ def recursion(a, b):
else:
return recursion(a+".", b+1)
#? int() float()
##? int() float()
recursion("a", 1.0)
# -----------------
@@ -86,11 +86,12 @@ exe[1].append
# default arguments
# -----------------
##? int() str()
func()
##? float() str()
func(1.0)
#? int()
func()[0]
#? float()
func(1.0)[0]
#? str()
func(1.0)[1]
# -----------------
# closures
@@ -134,9 +135,9 @@ exe2[1].upper
exe3 = args_func([1,""])[0]
##? []
#? []
exe3[1].real
##? ['upper']
#? ['upper']
exe3[1].upper
def args_func(arg1, *args):