1
0
forked from VimPlug/jedi

cleaned up evaluate.param

This commit is contained in:
Dave Halter
2014-01-07 14:44:39 +01:00
parent 1881a24e73
commit 8a9453872f
+16 -26
View File
@@ -53,9 +53,8 @@ def get_params(evaluator, func, var_args):
param_dict = {} param_dict = {}
for param in func.params: for param in func.params:
param_dict[str(param.get_name())] = param param_dict[str(param.get_name())] = param
# There may be calls, which don't fit all the params, this just ignores # There may be calls, which don't fit all the params, this just ignores it.
# it. var_arg_iterator = common.PushBackIterator(_var_args_iterator(evaluator, var_args))
var_arg_iterator = _get_var_args_iterator(evaluator, var_args)
non_matching_keys = [] non_matching_keys = []
keys_used = set() keys_used = set()
@@ -63,9 +62,8 @@ def get_params(evaluator, func, var_args):
for param in func.params[start_offset:]: for param in func.params[start_offset:]:
# The value and key can both be null. There, the defaults apply. # The value and key can both be null. There, the defaults apply.
# args / kwargs will just be empty arrays / dicts, respectively. # args / kwargs will just be empty arrays / dicts, respectively.
# Wrong value count is just ignored. If you try to test cases that # Wrong value count is just ignored. If you try to test cases that are
# are not allowed in Python, Jedi will maybe not show any # not allowed in Python, Jedi will maybe not show any completions.
# completions.
key, value = next(var_arg_iterator, (None, None)) key, value = next(var_arg_iterator, (None, None))
while key: while key:
keys_only = True keys_only = True
@@ -75,8 +73,7 @@ def get_params(evaluator, func, var_args):
non_matching_keys.append((key, value)) non_matching_keys.append((key, value))
else: else:
keys_used.add(str(key)) keys_used.add(str(key))
result.append(gen_param_name_copy(key_param, result.append(gen_param_name_copy(key_param, values=[value]))
values=[value]))
key, value = next(var_arg_iterator, (None, None)) key, value = next(var_arg_iterator, (None, None))
expression_list = param.expression_list() expression_list = param.expression_list()
@@ -111,17 +108,17 @@ def get_params(evaluator, func, var_args):
result.append(param.get_name()) result.append(param.get_name())
param.is_generated = True param.is_generated = True
else: else:
# If there is no assignment detail, that means there is # If there is no assignment detail, that means there is no
# no assignment, just the result. Therefore nothing has # assignment, just the result. Therefore nothing has to be
# to be returned. # returned.
values = [] values = []
# Just ignore all the params that are without a key, after one # Just ignore all the params that are without a key, after one keyword
# keyword argument was set. # argument was set.
if not ignore_creation and (not keys_only or expression_list[0] == '**'): if not ignore_creation and (not keys_only or expression_list[0] == '**'):
keys_used.add(str(key)) keys_used.add(str(key))
result.append(gen_param_name_copy(param, keys=keys, result.append(gen_param_name_copy(param, keys=keys, values=values,
values=values, array_type=array_type)) array_type=array_type))
if keys_only: if keys_only:
# sometimes param arguments are not completely written (which would # sometimes param arguments are not completely written (which would
@@ -131,11 +128,10 @@ def get_params(evaluator, func, var_args):
return result return result
def _get_var_args_iterator(evaluator, var_args): def _var_args_iterator(evaluator, var_args):
""" """
Yields a key/value pair, the key is None, if its not a named arg. Yields a key/value pair, the key is None, if its not a named arg.
""" """
def iterate():
# `var_args` is typically an Array, and not a list. # `var_args` is typically an Array, and not a list.
for stmt in var_args: for stmt in var_args:
if not isinstance(stmt, pr.Statement): if not isinstance(stmt, pr.Statement):
@@ -153,10 +149,8 @@ def _get_var_args_iterator(evaluator, var_args):
if not len(expression_list): if not len(expression_list):
continue continue
if expression_list[0] == '*': if expression_list[0] == '*':
arrays = evaluator.eval_expression_list(expression_list[1:])
# *args must be some sort of an array, otherwise -> ignore # *args must be some sort of an array, otherwise -> ignore
for array in evaluator.eval_expression_list(expression_list[1:]):
for array in arrays:
if isinstance(array, iterable.Array): if isinstance(array, iterable.Array):
for field_stmt in array: # yield from plz! for field_stmt in array: # yield from plz!
yield None, field_stmt yield None, field_stmt
@@ -165,8 +159,7 @@ def _get_var_args_iterator(evaluator, var_args):
yield None, _FakeStatement(field_stmt) yield None, _FakeStatement(field_stmt)
# **kwargs # **kwargs
elif expression_list[0] == '**': elif expression_list[0] == '**':
arrays = evaluator.eval_expression_list(expression_list[1:]) for array in evaluator.eval_expression_list(expression_list[1:]):
for array in arrays:
if isinstance(array, iterable.Array): if isinstance(array, iterable.Array):
for key_stmt, value_stmt in array.items(): for key_stmt, value_stmt in array.items():
# first index, is the key if syntactically correct # first index, is the key if syntactically correct
@@ -185,8 +178,6 @@ def _get_var_args_iterator(evaluator, var_args):
else: else:
yield None, stmt yield None, stmt
return iter(common.PushBackIterator(iterate()))
class _FakeSubModule(): class _FakeSubModule():
line_offset = 0 line_offset = 0
@@ -194,6 +185,5 @@ class _FakeSubModule():
class _FakeStatement(pr.Statement): class _FakeStatement(pr.Statement):
def __init__(self, content): def __init__(self, content):
cls = type(self)
p = 0, 0 p = 0, 0
super(cls, self).__init__(_FakeSubModule, [content], p, p) super(_FakeStatement, self).__init__(_FakeSubModule, [content], p, p)