mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-21 04:51:13 +08:00
fix issues with empty *args as inputs
This commit is contained in:
@@ -110,7 +110,6 @@ def search_params(evaluator, param):
|
|||||||
# only if we have the correct function we execute
|
# only if we have the correct function we execute
|
||||||
# it, otherwise just ignore it.
|
# it, otherwise just ignore it.
|
||||||
evaluator.follow_path(iter(last), s, scope)
|
evaluator.follow_path(iter(last), s, scope)
|
||||||
|
|
||||||
return listener.param_possibilities
|
return listener.param_possibilities
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class NameFinder(object):
|
|||||||
self.name_str = name_str
|
self.name_str = name_str
|
||||||
self.position = position
|
self.position = position
|
||||||
|
|
||||||
|
@debug.increase_indent
|
||||||
def find(self, scopes, resolve_decorator=True, search_global=False):
|
def find(self, scopes, resolve_decorator=True, search_global=False):
|
||||||
if unicode(self.name_str) == 'None':
|
if unicode(self.name_str) == 'None':
|
||||||
# Filter None, because it's really just a keyword, nobody wants to
|
# Filter None, because it's really just a keyword, nobody wants to
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class FakeSubModule():
|
|||||||
|
|
||||||
|
|
||||||
class FakeArray(pr.Array):
|
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)
|
p = (0, 0)
|
||||||
super(FakeArray, self).__init__(FakeSubModule, p, arr_type, parent)
|
super(FakeArray, self).__init__(FakeSubModule, p, arr_type, parent)
|
||||||
self.values = values
|
self.values = values
|
||||||
@@ -191,3 +191,14 @@ class FakeName(pr.Name):
|
|||||||
else:
|
else:
|
||||||
names = [(name_or_names, p)]
|
names = [(name_or_names, p)]
|
||||||
super(FakeName, self).__init__(FakeSubModule, names, p, p, parent)
|
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])
|
||||||
|
|||||||
@@ -114,13 +114,15 @@ def get_params(evaluator, func, var_args):
|
|||||||
if param.stars == 1:
|
if param.stars == 1:
|
||||||
# *args param
|
# *args param
|
||||||
array_type = pr.Array.TUPLE
|
array_type = pr.Array.TUPLE
|
||||||
values += va_values
|
lst_values = [va_values]
|
||||||
for key, va_values in var_arg_iterator:
|
for key, va_values in var_arg_iterator:
|
||||||
# Iterate until a key argument is found.
|
# Iterate until a key argument is found.
|
||||||
if key:
|
if key:
|
||||||
var_arg_iterator.push_back((key, va_values))
|
var_arg_iterator.push_back((key, va_values))
|
||||||
break
|
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:
|
elif param.stars == 2:
|
||||||
# **kwargs param
|
# **kwargs param
|
||||||
array_type = pr.Array.DICT
|
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
|
# *args must be some sort of an array, otherwise -> ignore
|
||||||
arrays = evaluator.eval_expression_list(expression_list[1:])
|
arrays = evaluator.eval_expression_list(expression_list[1:])
|
||||||
iterators = [_iterate_star_args(a) for a in arrays]
|
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]
|
yield None, [v for v in values if v is not None]
|
||||||
# **kwargs
|
# **kwargs
|
||||||
elif expression_list[0] == '**':
|
elif expression_list[0] == '**':
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ def nested_twice(*args1):
|
|||||||
nested_twice(2, 3)
|
nested_twice(2, 3)
|
||||||
#! 12 type-error-too-few-arguments
|
#! 12 type-error-too-few-arguments
|
||||||
nested_twice(2)
|
nested_twice(2)
|
||||||
|
#! 19 type-error-too-many-arguments
|
||||||
|
nested_twice(2, 3, 4)
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# **kwargs
|
# **kwargs
|
||||||
@@ -36,6 +38,8 @@ nested_twice(2)
|
|||||||
|
|
||||||
|
|
||||||
def kwargs_test(**kwargs):
|
def kwargs_test(**kwargs):
|
||||||
|
# TODO should not be here, but somewhere down there.
|
||||||
|
#! 14 type-error-multiple-values
|
||||||
return simple2(1, **kwargs)
|
return simple2(1, **kwargs)
|
||||||
|
|
||||||
kwargs_test(c=3, b=2)
|
kwargs_test(c=3, b=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user