mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +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`
|
: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:
|
if call_txt is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -587,7 +587,6 @@ class Script(object):
|
|||||||
self._pos, stmt)
|
self._pos, stmt)
|
||||||
debug.speed('func_call followed')
|
debug.speed('func_call followed')
|
||||||
|
|
||||||
key_name = None
|
|
||||||
if 0: # Change logic.
|
if 0: # Change logic.
|
||||||
try:
|
try:
|
||||||
# Access the trailers arglist node.
|
# Access the trailers arglist node.
|
||||||
|
|||||||
@@ -690,6 +690,7 @@ class CallSignature(Definition):
|
|||||||
|
|
||||||
for i, param in enumerate(self.params):
|
for i, param in enumerate(self.params):
|
||||||
# *args case
|
# *args case
|
||||||
|
print(param)
|
||||||
if param._name.get_definition().stars == 1:
|
if param._name.get_definition().stars == 1:
|
||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -28,14 +28,12 @@ py__getattribute__(evaluator, name) Returns a list of attribute values. The
|
|||||||
|
|
||||||
__
|
__
|
||||||
"""
|
"""
|
||||||
import copy
|
|
||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass, unicode, Python3Method
|
from jedi._compatibility import use_metaclass, unicode, Python3Method
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree as pr
|
||||||
from jedi.parser.tokenize import Token
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.cache import underscore_memoization
|
from jedi.cache import underscore_memoization
|
||||||
@@ -317,7 +315,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
for command in self.var.children]
|
for command in self.var.children]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@underscore_memoization
|
@memoize_default()
|
||||||
def name(self):
|
def name(self):
|
||||||
name = self.var.name
|
name = self.var.name
|
||||||
return helpers.FakeName(unicode(name), self, name.start_pos)
|
return helpers.FakeName(unicode(name), self, name.start_pos)
|
||||||
|
|||||||
@@ -163,21 +163,38 @@ class UserContext(object):
|
|||||||
"""
|
"""
|
||||||
index = 0
|
index = 0
|
||||||
level = 0
|
level = 0
|
||||||
|
next_must_be_name = False
|
||||||
|
next_is_key = False
|
||||||
|
key_name = None
|
||||||
for token in self._get_backwards_tokenizer(self.position):
|
for token in self._get_backwards_tokenizer(self.position):
|
||||||
tok_str = token.value
|
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 == '(':
|
if tok_str == '(':
|
||||||
level += 1
|
level += 1
|
||||||
if level == 1:
|
if level == 1:
|
||||||
|
next_must_be_name = True
|
||||||
|
level = 0
|
||||||
end = token.end_pos
|
end = token.end_pos
|
||||||
self._column_temp = self._line_length - end[1]
|
self._column_temp = self._line_length - end[1]
|
||||||
pos = self._line_temp + 1, self._column_temp
|
pos = self._line_temp + 1, self._column_temp
|
||||||
call, _ = self._calc_path_until_cursor(start_pos=pos)
|
|
||||||
return call, index
|
|
||||||
elif tok_str == ')':
|
elif tok_str == ')':
|
||||||
level -= 1
|
level -= 1
|
||||||
elif tok_str == ',':
|
elif tok_str == ',':
|
||||||
index += 1
|
index += 1
|
||||||
return None, 0
|
elif tok_str == '=':
|
||||||
|
next_is_key=True
|
||||||
|
return None, 0, None
|
||||||
|
|
||||||
def get_context(self, yield_positions=False):
|
def get_context(self, yield_positions=False):
|
||||||
self.get_path_until_cursor() # In case _start_cursor_pos is undefined.
|
self.get_path_until_cursor() # In case _start_cursor_pos is undefined.
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class TestCallSignatures(TestCase):
|
|||||||
signatures = Script(s).call_signatures()
|
signatures = Script(s).call_signatures()
|
||||||
assert len(signatures) == 1
|
assert len(signatures) == 1
|
||||||
x = [p.description for p in signatures[0].params]
|
x = [p.description for p in signatures[0].params]
|
||||||
assert x == ['*args']
|
assert x == ['args']
|
||||||
|
|
||||||
def test_additional_brackets(self):
|
def test_additional_brackets(self):
|
||||||
self._run('str((', 'str', 0)
|
self._run('str((', 'str', 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user