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