diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 20315a0d..c93730a3 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -365,8 +365,7 @@ class Script(object): :rtype: list of :class:`classes.CallSignature` """ - call_details = \ - helpers.get_call_signature_details(self._module_node, self._pos) + call_details = helpers.get_call_signature_details(self._module_node, self._pos) if call_details is None: return [] diff --git a/jedi/api/classes.py b/jedi/api/classes.py index f983217a..6b51d2a3 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -626,7 +626,7 @@ class CallSignature(Definition): return i return None - if self._call_details.call_index >= len(self.params): + if self._call_details.index >= len(self.params): for i, param in enumerate(self.params): tree_name = param._name.tree_name if tree_name is not None: @@ -634,7 +634,7 @@ class CallSignature(Definition): if tree_name.get_definition().star_count == 1: return i return None - return self._call_details.call_index + return self._call_details.index @property def params(self): @@ -657,7 +657,7 @@ class CallSignature(Definition): return '<%s: %s index=%r params=[%s]>' % ( type(self).__name__, self._name.string_name, - self._index, + self.index, self._params_str, ) diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index aa1358d2..e2fd67b9 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -159,10 +159,20 @@ def evaluate_goto_definition(evaluator, context, leaf): return definitions -CallDetails = namedtuple( - 'CallDetails', - ['bracket_leaf', 'call_index', 'keyword_name_str'] -) +class CallDetails(object): + def __init__(self, bracket_leaf, children, position): + ['bracket_leaf', 'call_index', 'keyword_name_str'] + self.bracket_leaf = bracket_leaf + self._children = children + self._position = position + + @property + def index(self): + return _get_index_and_key(self._children, self._position)[0] + + @property + def keyword_name_str(self): + return _get_index_and_key(self._children, self._position)[1] def _get_index_and_key(nodes, position): @@ -198,10 +208,7 @@ def _get_call_signature_details_from_error_node(node, position): if name is None: continue if name.type == 'name' or name.parent.type in ('trailer', 'atom'): - return CallDetails( - element, - *_get_index_and_key(children, position) - ) + return CallDetails(element, children, position) def get_call_signature_details(module, position): @@ -213,6 +220,7 @@ def get_call_signature_details(module, position): return None if leaf == ')': + # TODO is this ok? if leaf.end_pos == position: leaf = leaf.get_next_leaf() @@ -235,8 +243,7 @@ def get_call_signature_details(module, position): leaf = node.get_previous_leaf() if leaf is None: return None - return CallDetails( - node.children[0], *_get_index_and_key(node.children, position)) + return CallDetails(node.children[0], node.children, position) node = node.parent