fix issues with empty *args as inputs

This commit is contained in:
Dave Halter
2014-05-31 11:03:37 +02:00
parent f4a508ac53
commit 248cca2e5e
5 changed files with 22 additions and 5 deletions

View File

@@ -110,7 +110,6 @@ def search_params(evaluator, param):
# only if we have the correct function we execute
# it, otherwise just ignore it.
evaluator.follow_path(iter(last), s, scope)
return listener.param_possibilities
result = []

View File

@@ -35,6 +35,7 @@ class NameFinder(object):
self.name_str = name_str
self.position = position
@debug.increase_indent
def find(self, scopes, resolve_decorator=True, search_global=False):
if unicode(self.name_str) == 'None':
# Filter None, because it's really just a keyword, nobody wants to

View File

@@ -170,7 +170,7 @@ class FakeSubModule():
class FakeArray(pr.Array):
def __init__(self, values, parent, arr_type=pr.Array.LIST):
def __init__(self, values, parent=None, arr_type=pr.Array.LIST):
p = (0, 0)
super(FakeArray, self).__init__(FakeSubModule, p, arr_type, parent)
self.values = values
@@ -191,3 +191,14 @@ class FakeName(pr.Name):
else:
names = [(name_or_names, p)]
super(FakeName, self).__init__(FakeSubModule, names, p, p, parent)
def stmts_to_stmt(statements):
"""
Sometimes we want to have something like a result_set and unite some
statements in one.
"""
if len(statements) == 1:
return statements[0]
array = FakeArray(statements, arr_type=pr.Array.NOARRAY)
return FakeStatement([array])

View File

@@ -114,13 +114,15 @@ def get_params(evaluator, func, var_args):
if param.stars == 1:
# *args param
array_type = pr.Array.TUPLE
values += va_values
lst_values = [va_values]
for key, va_values in var_arg_iterator:
# Iterate until a key argument is found.
if key:
var_arg_iterator.push_back((key, va_values))
break
values += va_values
lst_values.append(va_values)
if lst_values[0]:
values = [helpers.stmts_to_stmt(v) for v in lst_values]
elif param.stars == 2:
# **kwargs param
array_type = pr.Array.DICT
@@ -202,7 +204,7 @@ def _var_args_iterator(evaluator, var_args):
# *args must be some sort of an array, otherwise -> ignore
arrays = evaluator.eval_expression_list(expression_list[1:])
iterators = [_iterate_star_args(a) for a in arrays]
for values in zip_longest(*iterators):
for values in list(zip_longest(*iterators)):
yield None, [v for v in values if v is not None]
# **kwargs
elif expression_list[0] == '**':

View File

@@ -29,6 +29,8 @@ def nested_twice(*args1):
nested_twice(2, 3)
#! 12 type-error-too-few-arguments
nested_twice(2)
#! 19 type-error-too-many-arguments
nested_twice(2, 3, 4)
# -----------------
# **kwargs
@@ -36,6 +38,8 @@ nested_twice(2)
def kwargs_test(**kwargs):
# TODO should not be here, but somewhere down there.
#! 14 type-error-multiple-values
return simple2(1, **kwargs)
kwargs_test(c=3, b=2)