Fixed named argument call signature stuff and issues with classes and call signature params.

This commit is contained in:
Dave Halter
2014-12-07 23:55:44 +01:00
parent bb747a83e8
commit b24bf29fc2
5 changed files with 24 additions and 9 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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)

View File

@@ -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.

View File

@@ -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)