mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
Fixed named argument call signature stuff and issues with classes and call signature params.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user