diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 86dd3ad3..22a417d1 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -571,7 +571,7 @@ class Script(object): :rtype: list of :class:`classes.CallSignature` """ - call_txt, call_index = self._user_context.call_signature() + call_txt, call_index, key_name = self._user_context.call_signature() if call_txt is None: return [] @@ -587,7 +587,6 @@ class Script(object): self._pos, stmt) debug.speed('func_call followed') - key_name = None if 0: # Change logic. try: # Access the trailers arglist node. diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 03fe0e44..18fd510c 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -690,6 +690,7 @@ class CallSignature(Definition): for i, param in enumerate(self.params): # *args case + print(param) if param._name.get_definition().stars == 1: return i return None diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 28175304..d985d7b1 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -28,14 +28,12 @@ py__getattribute__(evaluator, name) Returns a list of attribute values. The __ """ -import copy import os import pkgutil from itertools import chain from jedi._compatibility import use_metaclass, unicode, Python3Method from jedi.parser import tree as pr -from jedi.parser.tokenize import Token from jedi import debug from jedi import common from jedi.cache import underscore_memoization @@ -317,7 +315,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)): for command in self.var.children] @property - @underscore_memoization + @memoize_default() def name(self): name = self.var.name return helpers.FakeName(unicode(name), self, name.start_pos) diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index d0eff656..a9c72049 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -163,21 +163,38 @@ class UserContext(object): """ index = 0 level = 0 + next_must_be_name = False + next_is_key = False + key_name = None for token in self._get_backwards_tokenizer(self.position): tok_str = token.value + if next_must_be_name: + if token.type == tokenize.NAME: + call, _ = self._calc_path_until_cursor(start_pos=pos) + print(call, index, key_name) + return call, index, key_name + index = 0 + next_must_be_name = False + elif next_is_key: + if token.type == tokenize.NAME: + key_name = tok_str[::-1] + next_is_key = False + if tok_str == '(': level += 1 if level == 1: + next_must_be_name = True + level = 0 end = token.end_pos self._column_temp = self._line_length - end[1] pos = self._line_temp + 1, self._column_temp - call, _ = self._calc_path_until_cursor(start_pos=pos) - return call, index elif tok_str == ')': level -= 1 elif tok_str == ',': index += 1 - return None, 0 + elif tok_str == '=': + next_is_key=True + return None, 0, None def get_context(self, yield_positions=False): self.get_path_until_cursor() # In case _start_cursor_pos is undefined. diff --git a/test/test_api/test_call_signatures.py b/test/test_api/test_call_signatures.py index 46c40eac..56f9ef29 100644 --- a/test/test_api/test_call_signatures.py +++ b/test/test_api/test_call_signatures.py @@ -166,7 +166,7 @@ class TestCallSignatures(TestCase): signatures = Script(s).call_signatures() assert len(signatures) == 1 x = [p.description for p in signatures[0].params] - assert x == ['*args'] + assert x == ['args'] def test_additional_brackets(self): self._run('str((', 'str', 0)