1
0
forked from VimPlug/jedi

Cleanup even more param magic.

This commit is contained in:
Dave Halter
2016-11-02 16:29:32 +01:00
parent cd874cb052
commit 694a2e0769
+26 -29
View File
@@ -266,30 +266,29 @@ def get_params(evaluator, parent_context, func, var_args):
key, argument = next(var_arg_iterator, (None, default)) key, argument = next(var_arg_iterator, (None, default))
while key is not None: while key is not None:
keys_only = True keys_only = True
k = unicode(key)
try: try:
key_param = param_dict[unicode(key)] key_param = param_dict[key]
except KeyError: except KeyError:
non_matching_keys[key] = argument non_matching_keys[key] = argument
else: else:
result_params.append(ExecutedParam(key_param, var_args, argument)) if key in keys_used:
had_multiple_value_error = True
if k in keys_used: m = ("TypeError: %s() got multiple values for keyword argument '%s'."
had_multiple_value_error = True % (func.name, key))
m = ("TypeError: %s() got multiple values for keyword argument '%s'." calling_va = _get_calling_var_args(evaluator, var_args)
% (func.name, k)) if calling_va is not None:
calling_va = _get_calling_var_args(evaluator, var_args) analysis.add(evaluator, 'type-error-multiple-values',
if calling_va is not None: calling_va, message=m)
analysis.add(evaluator, 'type-error-multiple-values', else:
calling_va, message=m) keys_used[key] = ExecutedParam(key_param, var_args, argument)
else:
try:
keys_used[k] = result_params[-1]
except IndexError:
# TODO this is wrong stupid and whatever.
pass
key, argument = next(var_arg_iterator, (None, None)) key, argument = next(var_arg_iterator, (None, None))
try:
result_params.append(keys_used[param.name.value])
continue
except KeyError:
pass
if param.stars == 1: if param.stars == 1:
# *args param # *args param
lazy_context_list = [] lazy_context_list = []
@@ -312,7 +311,10 @@ def get_params(evaluator, parent_context, func, var_args):
# normal param # normal param
if argument is None: if argument is None:
# No value: Return an empty container # No value: Return an empty container
result_arg = context.LazyUnknownContext() if param.default is None:
result_arg = context.LazyUnknownContext()
else:
result_arg = context.LazyTreeContext(parent_context, param.default)
if not keys_only: if not keys_only:
calling_va = var_args.get_calling_var_args() calling_va = var_args.get_calling_var_args()
if calling_va is not None: if calling_va is not None:
@@ -322,10 +324,8 @@ def get_params(evaluator, parent_context, func, var_args):
else: else:
result_arg = argument result_arg = argument
# Now add to result if it's not one of the previously covered cases. result_params.append(ExecutedParam(param, var_args, result_arg))
if (not keys_only or param.stars == 2): keys_used[param.name.value] = result_params[-1]
result_params.append(ExecutedParam(param, var_args, result_arg))
keys_used[unicode(param.name)] = result_params[-1]
if keys_only: if keys_only:
# All arguments should be handed over to the next function. It's not # All arguments should be handed over to the next function. It's not
@@ -333,9 +333,6 @@ def get_params(evaluator, parent_context, func, var_args):
# there's nothing to find for certain names. # there's nothing to find for certain names.
for k in set(param_dict) - set(keys_used): for k in set(param_dict) - set(keys_used):
param = param_dict[k] param = param_dict[k]
result_arg = (context.LazyUnknownContext() if param.default is None else
context.LazyTreeContext(parent_context, param.default))
result_params.append(ExecutedParam(param, var_args, result_arg))
if not (non_matching_keys or had_multiple_value_error or if not (non_matching_keys or had_multiple_value_error or
param.stars or param.default): param.stars or param.default):
@@ -351,12 +348,12 @@ def get_params(evaluator, parent_context, func, var_args):
% (func.name, key) % (func.name, key)
analysis.add(evaluator, 'type-error-keyword-argument', argument.whatever, message=m) analysis.add(evaluator, 'type-error-keyword-argument', argument.whatever, message=m)
remaining_params = list(var_arg_iterator) remaining_arguments = list(var_arg_iterator)
if remaining_params: if remaining_arguments:
m = _error_argument_count(func, len(unpacked_va)) m = _error_argument_count(func, len(unpacked_va))
# Just report an error for the first param that is not needed (like # Just report an error for the first param that is not needed (like
# cPython). # cPython).
first_key, first_values = remaining_params[0] first_key, first_values = remaining_arguments[0]
# TODO REENABLE # TODO REENABLE
for v in []:#first_values: for v in []:#first_values:
if first_key is not None: if first_key is not None: