mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-23 22:01:26 +08:00
stars -> star_count.
This commit is contained in:
@@ -627,7 +627,7 @@ class CallSignature(Definition):
|
||||
if self.params:
|
||||
param_name = self.params[-1]._name
|
||||
if param_name.tree_name is not None:
|
||||
if param_name.tree_name.get_definition().stars == 2:
|
||||
if param_name.tree_name.get_definition().star_count == 2:
|
||||
return i
|
||||
return None
|
||||
|
||||
@@ -636,7 +636,7 @@ class CallSignature(Definition):
|
||||
tree_name = param._name.tree_name
|
||||
if tree_name is not None:
|
||||
# *args case
|
||||
if tree_name.get_definition().stars == 1:
|
||||
if tree_name.get_definition().star_count == 1:
|
||||
return i
|
||||
return None
|
||||
return self._index
|
||||
|
||||
@@ -22,7 +22,7 @@ def get_call_signature_param_names(call_signatures):
|
||||
# public API and we don't want to make the internal
|
||||
# Name object public.
|
||||
tree_param = tree.search_ancestor(tree_name, 'param')
|
||||
if tree_param.stars == 0: # no *args/**kwargs
|
||||
if tree_param.star_count == 0: # no *args/**kwargs
|
||||
yield p._name
|
||||
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@ class TreeArguments(AbstractArguments):
|
||||
|
||||
def unpack(self, func=None):
|
||||
named_args = []
|
||||
for stars, el in self._split():
|
||||
if stars == 1:
|
||||
for star_count, el in self._split():
|
||||
if star_count == 1:
|
||||
arrays = self.context.eval_node(el)
|
||||
iterators = [_iterate_star_args(self.context, a, el, func)
|
||||
for a in arrays]
|
||||
@@ -124,7 +124,7 @@ class TreeArguments(AbstractArguments):
|
||||
yield None, context.get_merged_lazy_context(
|
||||
[v for v in values if v is not None]
|
||||
)
|
||||
elif stars == 2:
|
||||
elif star_count == 2:
|
||||
arrays = self._evaluator.eval_element(self.context, el)
|
||||
for dct in arrays:
|
||||
for key, values in _star_star_dict(self.context, dct, el, func):
|
||||
@@ -148,12 +148,12 @@ class TreeArguments(AbstractArguments):
|
||||
yield named_arg
|
||||
|
||||
def as_tree_tuple_objects(self):
|
||||
for stars, argument in self._split():
|
||||
for star_count, argument in self._split():
|
||||
if argument.type == 'argument':
|
||||
argument, default = argument.children[::2]
|
||||
else:
|
||||
default = None
|
||||
yield argument, default, stars
|
||||
yield argument, default, star_count
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.argument_node)
|
||||
@@ -168,8 +168,8 @@ class TreeArguments(AbstractArguments):
|
||||
break
|
||||
|
||||
old_arguments_list.append(arguments)
|
||||
for name, default, stars in reversed(list(arguments.as_tree_tuple_objects())):
|
||||
if not stars or not isinstance(name, tree.Name):
|
||||
for name, default, star_count in reversed(list(arguments.as_tree_tuple_objects())):
|
||||
if not star_count or not isinstance(name, tree.Name):
|
||||
continue
|
||||
|
||||
names = self._evaluator.goto(arguments.context, name)
|
||||
@@ -274,7 +274,7 @@ def get_params(evaluator, parent_context, func, var_args):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
if param.stars == 1:
|
||||
if param.star_count == 1:
|
||||
# *args param
|
||||
lazy_context_list = []
|
||||
if argument is not None:
|
||||
@@ -287,7 +287,7 @@ def get_params(evaluator, parent_context, func, var_args):
|
||||
lazy_context_list.append(argument)
|
||||
seq = iterable.FakeSequence(evaluator, 'tuple', lazy_context_list)
|
||||
result_arg = context.LazyKnownContext(seq)
|
||||
elif param.stars == 2:
|
||||
elif param.star_count == 2:
|
||||
# **kwargs param
|
||||
dct = iterable.FakeDict(evaluator, dict(non_matching_keys))
|
||||
result_arg = context.LazyKnownContext(dct)
|
||||
@@ -320,7 +320,7 @@ def get_params(evaluator, parent_context, func, var_args):
|
||||
param = param_dict[k]
|
||||
|
||||
if not (non_matching_keys or had_multiple_value_error or
|
||||
param.stars or param.default):
|
||||
param.star_count or param.default):
|
||||
# add a warning only if there's not another one.
|
||||
for node in var_args.get_calling_nodes():
|
||||
m = _error_argument_count(func, len(unpacked_va))
|
||||
@@ -380,7 +380,7 @@ def _star_star_dict(context, array, input_node, func):
|
||||
|
||||
|
||||
def _error_argument_count(func, actual_count):
|
||||
default_arguments = sum(1 for p in func.params if p.default or p.stars)
|
||||
default_arguments = sum(1 for p in func.params if p.default or p.star_count)
|
||||
|
||||
if default_arguments == 0:
|
||||
before = 'exactly '
|
||||
@@ -391,11 +391,11 @@ def _error_argument_count(func, actual_count):
|
||||
|
||||
|
||||
def create_default_param(parent_context, param):
|
||||
if param.stars == 1:
|
||||
if param.star_count == 1:
|
||||
result_arg = context.LazyKnownContext(
|
||||
iterable.FakeSequence(parent_context.evaluator, 'tuple', [])
|
||||
)
|
||||
elif param.stars == 2:
|
||||
elif param.star_count == 2:
|
||||
result_arg = context.LazyKnownContext(
|
||||
iterable.FakeDict(parent_context.evaluator, {})
|
||||
)
|
||||
|
||||
@@ -81,18 +81,18 @@ def _fix_forward_reference(context, node):
|
||||
|
||||
@memoize_default()
|
||||
def follow_param(context, param):
|
||||
annotation = param.annotation()
|
||||
annotation = param.get_annotation()
|
||||
return _evaluate_for_annotation(context, annotation)
|
||||
|
||||
|
||||
def py__annotations__(funcdef):
|
||||
return_annotation = funcdef.annotation()
|
||||
return_annotation = funcdef.get_annotation()
|
||||
if return_annotation:
|
||||
dct = {'return': return_annotation}
|
||||
else:
|
||||
dct = {}
|
||||
for function_param in funcdef.params:
|
||||
param_annotation = function_param.annotation()
|
||||
param_annotation = function_param.get_annotation()
|
||||
if param_annotation is not None:
|
||||
dct[function_param.name.value] = param_annotation
|
||||
return dct
|
||||
|
||||
@@ -588,7 +588,7 @@ class Function(ClassOrFunc):
|
||||
def is_generator(self):
|
||||
return bool(self.yields)
|
||||
|
||||
def annotation(self):
|
||||
def get_annotation(self):
|
||||
try:
|
||||
if self.children[3] == "->":
|
||||
return self.children[4]
|
||||
@@ -656,7 +656,7 @@ class Lambda(Function):
|
||||
def is_generator(self):
|
||||
return False
|
||||
|
||||
def annotation(self):
|
||||
def get_annotation(self):
|
||||
# lambda functions do not support annotations
|
||||
return None
|
||||
|
||||
@@ -1053,7 +1053,7 @@ class Param(PythonBaseNode):
|
||||
child.parent = self
|
||||
|
||||
@property
|
||||
def stars(self):
|
||||
def star_count(self):
|
||||
first = self.children[0]
|
||||
if first in ('*', '**'):
|
||||
return len(first.value)
|
||||
@@ -1066,7 +1066,7 @@ class Param(PythonBaseNode):
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def annotation(self):
|
||||
def get_annotation(self):
|
||||
tfpdef = self._tfpdef()
|
||||
if tfpdef.type == 'tfpdef':
|
||||
assert tfpdef.children[1] == ":"
|
||||
@@ -1105,16 +1105,16 @@ class Param(PythonBaseNode):
|
||||
def get_parent_function(self):
|
||||
return search_ancestor(self, ('funcdef', 'lambda'))
|
||||
|
||||
def __repr__(self):
|
||||
default = '' if self.default is None else '=%s' % self.default.get_code()
|
||||
return '<%s: %s>' % (type(self).__name__, str(self._tfpdef()) + default)
|
||||
|
||||
def get_description(self):
|
||||
children = self.children
|
||||
if children[-1] == ',':
|
||||
children = children[:-1]
|
||||
return self._get_code_for_children(children, False, False)
|
||||
|
||||
def __repr__(self):
|
||||
default = '' if self.default is None else '=%s' % self.default.get_code()
|
||||
return '<%s: %s>' % (type(self).__name__, str(self._tfpdef()) + default)
|
||||
|
||||
|
||||
class CompFor(PythonBaseNode):
|
||||
type = 'comp_for'
|
||||
|
||||
@@ -58,9 +58,9 @@ class TestsFunctionAndLambdaParsing(object):
|
||||
def test_annotation(self, node, expected):
|
||||
expected_annotation = expected.get('annotation', None)
|
||||
if expected_annotation is None:
|
||||
assert node.annotation() is None
|
||||
assert node.get_annotation() is None
|
||||
else:
|
||||
assert node.annotation().value == expected_annotation
|
||||
assert node.get_annotation().value == expected_annotation
|
||||
|
||||
def test_get_call_signature(self, node, expected):
|
||||
assert node.get_call_signature() == expected['call_sig']
|
||||
|
||||
Reference in New Issue
Block a user