forked from VimPlug/jedi
Restructure ExecutedParam so that it works better with generated instances.
This commit is contained in:
@@ -144,31 +144,24 @@ class Arguments(pr.Base):
|
|||||||
|
|
||||||
class ExecutedParam(pr.Param):
|
class ExecutedParam(pr.Param):
|
||||||
"""Fake a param and give it values."""
|
"""Fake a param and give it values."""
|
||||||
def __init__(self, values):
|
def __init__(self, original_param, var_args, values):
|
||||||
self.values = values
|
self._original_param = original_param
|
||||||
|
self.var_args = var_args
|
||||||
@classmethod
|
self._values = values
|
||||||
def from_param(cls, values, param, parent, var_args):
|
|
||||||
instance = cls(values)
|
|
||||||
|
|
||||||
instance.original_param = param
|
|
||||||
instance.parent = parent
|
|
||||||
instance.var_args = var_args
|
|
||||||
return instance
|
|
||||||
|
|
||||||
def eval(self, evaluator):
|
def eval(self, evaluator):
|
||||||
types = []
|
types = []
|
||||||
for v in self.values:
|
for v in self._values:
|
||||||
types += evaluator.eval_element(v)
|
types += evaluator.eval_element(v)
|
||||||
return types
|
return types
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def position_nr(self):
|
def position_nr(self):
|
||||||
# Need to use the original logic here, because it uses the parent.
|
# Need to use the original logic here, because it uses the parent.
|
||||||
return self.original_param.position_nr
|
return self._original_param.position_nr
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.original_param, name)
|
return getattr(self._original_param, name)
|
||||||
|
|
||||||
|
|
||||||
def _get_calling_var_args(evaluator, var_args):
|
def _get_calling_var_args(evaluator, var_args):
|
||||||
@@ -227,8 +220,8 @@ def get_params(evaluator, func, var_args):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
non_matching_keys[key] += va_values
|
non_matching_keys[key] += va_values
|
||||||
else:
|
else:
|
||||||
result.append(_gen_param_name_copy(evaluator, func, var_args,
|
result.append(_gen_param_name_copy(evaluator, key_param, var_args,
|
||||||
key_param, values=va_values))
|
va_values))
|
||||||
|
|
||||||
if k in keys_used:
|
if k in keys_used:
|
||||||
had_multiple_value_error = True
|
had_multiple_value_error = True
|
||||||
@@ -280,8 +273,8 @@ def get_params(evaluator, func, var_args):
|
|||||||
|
|
||||||
# Now add to result if it's not one of the previously covered cases.
|
# Now add to result if it's not one of the previously covered cases.
|
||||||
if (not keys_only or param.stars == 2):
|
if (not keys_only or param.stars == 2):
|
||||||
result.append(_gen_param_name_copy(evaluator, func, var_args, param,
|
result.append(_gen_param_name_copy(evaluator, param, var_args,
|
||||||
values=values))
|
values))
|
||||||
keys_used[unicode(param.get_name())] = result[-1]
|
keys_used[unicode(param.get_name())] = result[-1]
|
||||||
|
|
||||||
if keys_only:
|
if keys_only:
|
||||||
@@ -291,8 +284,7 @@ def get_params(evaluator, func, var_args):
|
|||||||
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]
|
||||||
values = [] if param.default is None else [param.default]
|
values = [] if param.default is None else [param.default]
|
||||||
result.append(_gen_param_name_copy(evaluator, func, var_args,
|
result.append(_gen_param_name_copy(evaluator, param, var_args, values))
|
||||||
param, values))
|
|
||||||
|
|
||||||
if not (non_matching_keys or had_multiple_value_error
|
if not (non_matching_keys or had_multiple_value_error
|
||||||
or param.stars or param.default):
|
or param.stars or param.default):
|
||||||
@@ -378,11 +370,11 @@ def _star_star_dict(evaluator, array, input_node, func):
|
|||||||
return dict(dct)
|
return dict(dct)
|
||||||
|
|
||||||
|
|
||||||
def _gen_param_name_copy(evaluator, func, var_args, param, values=()):
|
def _gen_param_name_copy(evaluator, param, var_args, values):
|
||||||
"""
|
"""
|
||||||
Create a param with the original scope (of varargs) as parent.
|
Create a param with the original scope (of varargs) as parent.
|
||||||
"""
|
"""
|
||||||
new_param = ExecutedParam.from_param(values, param, func, var_args)
|
new_param = ExecutedParam(param, var_args, values)
|
||||||
name = copy.copy(param.get_name())
|
name = copy.copy(param.get_name())
|
||||||
name.parent = new_param
|
name.parent = new_param
|
||||||
return name
|
return name
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
and compiled.builtin == base.get_parent_until():
|
and compiled.builtin == base.get_parent_until():
|
||||||
# compare the module path with the builtin name.
|
# compare the module path with the builtin name.
|
||||||
self.var_args = iterable.check_array_instances(evaluator, self)
|
self.var_args = iterable.check_array_instances(evaluator, self)
|
||||||
else:
|
elif not is_generated:
|
||||||
# Need to execute the __init__ function, because the dynamic param
|
# Need to execute the __init__ function, because the dynamic param
|
||||||
# searching needs it.
|
# searching needs it.
|
||||||
try:
|
try:
|
||||||
@@ -157,7 +157,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
if self_name is None:
|
if self_name is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if sub.name.value == '__init__':
|
if sub.name.value == '__init__' and not self.is_generated:
|
||||||
# ``__init__`` is special because the params need are injected
|
# ``__init__`` is special because the params need are injected
|
||||||
# this way. Therefore an execution is necessary.
|
# this way. Therefore an execution is necessary.
|
||||||
if not sub.get_decorators():
|
if not sub.get_decorators():
|
||||||
|
|||||||
Reference in New Issue
Block a user