forked from VimPlug/jedi
direct param evaluation
This commit is contained in:
@@ -341,8 +341,7 @@ class NameFinder(object):
|
|||||||
# this means that there are no default params,
|
# this means that there are no default params,
|
||||||
# so just ignore it.
|
# so just ignore it.
|
||||||
return res_new
|
return res_new
|
||||||
return res_new + list(chain.from_iterable(evaluator.eval_element(v)
|
return res_new + param.eval(self._evaluator)
|
||||||
for v in param.values))
|
|
||||||
|
|
||||||
def _handle_for_loops(self, loop):
|
def _handle_for_loops(self, loop):
|
||||||
# Take the first statement (for has always only one`in`).
|
# Take the first statement (for has always only one`in`).
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ class Arguments(object):
|
|||||||
if pr.is_node(el, 'argument'):
|
if pr.is_node(el, 'argument'):
|
||||||
named_args.append(el.children[::2])
|
named_args.append(el.children[::2])
|
||||||
else:
|
else:
|
||||||
yield None, [el]
|
yield None, el
|
||||||
|
|
||||||
for key_arg in named_args:
|
for key_arg in named_args:
|
||||||
# TODO its always only one value?
|
# TODO its always only one value?
|
||||||
yield key_arg[0], [key_arg[1]]
|
yield key_arg[0], key_arg[1]
|
||||||
|
|
||||||
def _reorder_var_args(var_args):
|
def _reorder_var_args(var_args):
|
||||||
named_index = None
|
named_index = None
|
||||||
@@ -125,6 +125,15 @@ class ExecutedParam(pr.Param):
|
|||||||
instance.var_args = var_args
|
instance.var_args = var_args
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
def eval(self, evaluator):
|
||||||
|
types = []
|
||||||
|
for v in self.values:
|
||||||
|
if isinstance(v, (pr.Simple, pr.Name, pr.Literal)):
|
||||||
|
types += evaluator.eval_element(v)
|
||||||
|
else:
|
||||||
|
types.append(v)
|
||||||
|
return types
|
||||||
|
|
||||||
|
|
||||||
def _get_calling_var_args(evaluator, var_args):
|
def _get_calling_var_args(evaluator, var_args):
|
||||||
old_var_args = None
|
old_var_args = None
|
||||||
@@ -167,24 +176,23 @@ def get_params(evaluator, func, var_args):
|
|||||||
non_matching_keys = []
|
non_matching_keys = []
|
||||||
keys_used = set()
|
keys_used = set()
|
||||||
keys_only = False
|
keys_only = False
|
||||||
va_values = None
|
|
||||||
had_multiple_value_error = False
|
had_multiple_value_error = False
|
||||||
for param in func.params:
|
for param in func.params:
|
||||||
# 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 are
|
# Wrong value count is just ignored. If you try to test cases that are
|
||||||
# not allowed in Python, Jedi will maybe not show any completions.
|
# not allowed in Python, Jedi will maybe not show any completions.
|
||||||
key, va_values = next(var_arg_iterator, (None, []))
|
key, va_value = next(var_arg_iterator, (None, []))
|
||||||
while key:
|
while key:
|
||||||
keys_only = True
|
keys_only = True
|
||||||
k = unicode(key)
|
k = unicode(key)
|
||||||
try:
|
try:
|
||||||
key_param = param_dict[unicode(key)]
|
key_param = param_dict[unicode(key)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
non_matching_keys.append((key, va_values))
|
non_matching_keys.append((key, va_value))
|
||||||
else:
|
else:
|
||||||
result.append(_gen_param_name_copy(evaluator, func, var_args,
|
result.append(_gen_param_name_copy(evaluator, func, var_args,
|
||||||
key_param, values=va_values))
|
key_param, values=[va_value]))
|
||||||
|
|
||||||
if k in keys_used:
|
if k in keys_used:
|
||||||
had_multiple_value_error = True
|
had_multiple_value_error = True
|
||||||
@@ -196,7 +204,7 @@ def get_params(evaluator, func, var_args):
|
|||||||
calling_va, message=m)
|
calling_va, message=m)
|
||||||
else:
|
else:
|
||||||
keys_used.add(k)
|
keys_used.add(k)
|
||||||
key, va_values = next(var_arg_iterator, (None, []))
|
key, va_value = next(var_arg_iterator, (None, None))
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
values = []
|
values = []
|
||||||
@@ -205,15 +213,18 @@ 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
|
||||||
lst_values = [va_values]
|
lst_values = []
|
||||||
for key, va_values in var_arg_iterator:
|
for key, va_value 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_value))
|
||||||
break
|
break
|
||||||
lst_values.append(va_values)
|
lst_values.append(va_value)
|
||||||
if lst_values[0]:
|
print(lst_values)
|
||||||
values = [helpers.stmts_to_stmt(v) for v in lst_values]
|
if lst_values:
|
||||||
|
values = [iterable.FakeArray(evaluator, tuple(lst_values),
|
||||||
|
pr.Array.TUPLE)]
|
||||||
|
#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
|
||||||
@@ -223,8 +234,8 @@ def get_params(evaluator, func, var_args):
|
|||||||
non_matching_keys = []
|
non_matching_keys = []
|
||||||
else:
|
else:
|
||||||
# normal param
|
# normal param
|
||||||
if va_values:
|
if va_value is not None:
|
||||||
values = va_values
|
values = [va_value]
|
||||||
else:
|
else:
|
||||||
if param.default is not None:
|
if param.default is not None:
|
||||||
# No value: Return the default values.
|
# No value: Return the default values.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ from jedi.parser.tokenize import Token
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.cache import underscore_memoization
|
from jedi.cache import underscore_memoization
|
||||||
from jedi.evaluate.cache import memoize_default, CachedMetaClass
|
from jedi.evaluate.cache import memoize_default, CachedMetaClass, NO_DEFAULT
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import recursion
|
from jedi.evaluate import recursion
|
||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
@@ -588,7 +588,7 @@ class FunctionExecution(Executed):
|
|||||||
def names_dict(self):
|
def names_dict(self):
|
||||||
return LazyDict(self.base.names_dict, self._copy_list)
|
return LazyDict(self.base.names_dict, self._copy_list)
|
||||||
|
|
||||||
@memoize_default(default=())
|
@memoize_default(default=NO_DEFAULT)
|
||||||
def _get_params(self):
|
def _get_params(self):
|
||||||
"""
|
"""
|
||||||
This returns the params for an TODO and is injected as a
|
This returns the params for an TODO and is injected as a
|
||||||
|
|||||||
Reference in New Issue
Block a user