forked from VimPlug/jedi
Make sure that equals will only be added to keyword arguments and not just randomly
This commit is contained in:
@@ -456,11 +456,7 @@ class Completion(BaseDefinition):
|
|||||||
and self.type == 'function':
|
and self.type == 'function':
|
||||||
append = '('
|
append = '('
|
||||||
|
|
||||||
if self._name.api_type == 'param' and self._stack is not None:
|
self._name.api_type
|
||||||
nonterminals = [stack_node.nonterminal for stack_node in self._stack]
|
|
||||||
if 'trailer' in nonterminals and 'argument' not in nonterminals:
|
|
||||||
# TODO this doesn't work for nested calls.
|
|
||||||
append += '='
|
|
||||||
|
|
||||||
name = self._name.get_public_name()
|
name = self._name.get_public_name()
|
||||||
if like_name:
|
if like_name:
|
||||||
|
|||||||
@@ -19,11 +19,17 @@ from jedi.inference.base_value import ValueSet
|
|||||||
from jedi.inference.helpers import infer_call_of_leaf, parse_dotted_names
|
from jedi.inference.helpers import infer_call_of_leaf, parse_dotted_names
|
||||||
from jedi.inference.context import get_global_filters
|
from jedi.inference.context import get_global_filters
|
||||||
from jedi.inference.value import TreeInstance, ModuleValue
|
from jedi.inference.value import TreeInstance, ModuleValue
|
||||||
|
from jedi.inference.names import ParamNameWrapper
|
||||||
from jedi.inference.gradual.conversion import convert_values
|
from jedi.inference.gradual.conversion import convert_values
|
||||||
from jedi.parser_utils import cut_value_at_position
|
from jedi.parser_utils import cut_value_at_position
|
||||||
from jedi.plugins import plugin_manager
|
from jedi.plugins import plugin_manager
|
||||||
|
|
||||||
|
|
||||||
|
class ParamNameWithEquals(ParamNameWrapper):
|
||||||
|
def get_public_name(self):
|
||||||
|
return self.string_name + '='
|
||||||
|
|
||||||
|
|
||||||
def get_signature_param_names(signatures):
|
def get_signature_param_names(signatures):
|
||||||
# add named params
|
# add named params
|
||||||
for call_sig in signatures:
|
for call_sig in signatures:
|
||||||
@@ -31,7 +37,7 @@ def get_signature_param_names(signatures):
|
|||||||
# Allow protected access, because it's a public API.
|
# Allow protected access, because it's a public API.
|
||||||
if p._name.get_kind() in (Parameter.POSITIONAL_OR_KEYWORD,
|
if p._name.get_kind() in (Parameter.POSITIONAL_OR_KEYWORD,
|
||||||
Parameter.KEYWORD_ONLY):
|
Parameter.KEYWORD_ONLY):
|
||||||
yield p._name
|
yield ParamNameWithEquals(p._name)
|
||||||
|
|
||||||
|
|
||||||
def filter_names(inference_state, completion_names, stack, like_name, fuzzy):
|
def filter_names(inference_state, completion_names, stack, like_name, fuzzy):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Named Params:
|
|||||||
def a(abc):
|
def a(abc):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#? 5 ['abc']
|
#? 5 ['abc=']
|
||||||
a(abc)
|
a(abc)
|
||||||
|
|
||||||
|
|
||||||
@@ -24,14 +24,14 @@ a(some_kwargs)
|
|||||||
def multiple(foo, bar):
|
def multiple(foo, bar):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#? 17 ['bar']
|
#? 17 ['bar=']
|
||||||
multiple(foo, bar)
|
multiple(foo, bar)
|
||||||
|
|
||||||
#? ['bar']
|
#? ['bar=']
|
||||||
multiple(foo, bar
|
multiple(foo, bar
|
||||||
|
|
||||||
my_lambda = lambda lambda_param: lambda_param + 1
|
my_lambda = lambda lambda_param: lambda_param + 1
|
||||||
#? 22 ['lambda_param']
|
#? 22 ['lambda_param=']
|
||||||
my_lambda(lambda_param)
|
my_lambda(lambda_param)
|
||||||
|
|
||||||
# __call__ / __init__
|
# __call__ / __init__
|
||||||
@@ -45,15 +45,15 @@ class Test(object):
|
|||||||
def test(self, blub):
|
def test(self, blub):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#? 10 ['hello_other']
|
#? 10 ['hello_other=']
|
||||||
Test(hello=)
|
Test(hello=)
|
||||||
#? 12 ['hello']
|
#? 12 ['hello=']
|
||||||
Test()(hello=)
|
Test()(hello=)
|
||||||
#? 11 []
|
#? 11 []
|
||||||
Test()(self=)
|
Test()(self=)
|
||||||
#? 16 []
|
#? 16 []
|
||||||
Test().test(self=)
|
Test().test(self=)
|
||||||
#? 16 ['blub']
|
#? 16 ['blub=']
|
||||||
Test().test(blub=)
|
Test().test(blub=)
|
||||||
|
|
||||||
# builtins
|
# builtins
|
||||||
@@ -65,7 +65,7 @@ any(iterable=)
|
|||||||
def foo(xyz):
|
def foo(xyz):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#? 7 ['xyz']
|
#? 7 ['xyz=']
|
||||||
foo(xyz)
|
foo(xyz)
|
||||||
# No completion should be possible if it's not a simple name
|
# No completion should be possible if it's not a simple name
|
||||||
#? 17 []
|
#? 17 []
|
||||||
@@ -81,11 +81,11 @@ x = " "; foo(xyz[xyz)
|
|||||||
#? 20 []
|
#? 20 []
|
||||||
x = " "; foo(xyz[(xyz)
|
x = " "; foo(xyz[(xyz)
|
||||||
|
|
||||||
#? 8 ['xyz']
|
#? 8 ['xyz=']
|
||||||
@foo(xyz)
|
@foo(xyz)
|
||||||
def x(): pass
|
def x(): pass
|
||||||
|
|
||||||
@str
|
@str
|
||||||
#? 8 ['xyz']
|
#? 8 ['xyz=']
|
||||||
@foo(xyz)
|
@foo(xyz)
|
||||||
def x(): pass
|
def x(): pass
|
||||||
|
|||||||
@@ -149,6 +149,18 @@ def test_with_stmt_error_recovery(Script):
|
|||||||
assert Script('with open('') as foo: foo.\na').complete(line=1)
|
assert Script('with open('') as foo: foo.\na').complete(line=1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_function_param_usage(Script):
|
||||||
|
c, = Script('def func(foo_value):\n str(foo_valu').complete()
|
||||||
|
assert c.complete == 'e'
|
||||||
|
assert c.name == 'foo_value'
|
||||||
|
|
||||||
|
c1, c2 = Script('def func(foo_value):\n func(foo_valu').complete()
|
||||||
|
assert c1.complete == 'e'
|
||||||
|
assert c1.name == 'foo_value'
|
||||||
|
assert c2.complete == 'e='
|
||||||
|
assert c2.name == 'foo_value='
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'code, has_keywords', (
|
'code, has_keywords', (
|
||||||
('', True),
|
('', True),
|
||||||
|
|||||||
@@ -311,8 +311,8 @@ def test_param_completion():
|
|||||||
|
|
||||||
lambd = lambda xyz: 3
|
lambd = lambda xyz: 3
|
||||||
|
|
||||||
_assert_interpreter_complete('foo(bar', locals(), ['bar'])
|
_assert_interpreter_complete('foo(bar', locals(), ['bar='])
|
||||||
assert bool(jedi.Interpreter('lambd(xyz', [locals()]).complete()) == is_py3
|
_assert_interpreter_complete('lambd(xyz', locals(), ['xyz='])
|
||||||
|
|
||||||
|
|
||||||
def test_endless_yield():
|
def test_endless_yield():
|
||||||
@@ -357,7 +357,7 @@ def test_keyword_argument():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
c, = jedi.Interpreter("f(some_keyw", [{'f': f}]).complete()
|
c, = jedi.Interpreter("f(some_keyw", [{'f': f}]).complete()
|
||||||
assert c.name == 'some_keyword_argument'
|
assert c.name == 'some_keyword_argument='
|
||||||
assert c.complete == 'ord_argument='
|
assert c.complete == 'ord_argument='
|
||||||
|
|
||||||
# This needs inspect.signature to work.
|
# This needs inspect.signature to work.
|
||||||
@@ -365,7 +365,7 @@ def test_keyword_argument():
|
|||||||
# Make it impossible for jedi to find the source of the function.
|
# Make it impossible for jedi to find the source of the function.
|
||||||
f.__name__ = 'xSOMETHING'
|
f.__name__ = 'xSOMETHING'
|
||||||
c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).complete()
|
c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).complete()
|
||||||
assert c.name == 'some_keyword_argument'
|
assert c.name == 'some_keyword_argument='
|
||||||
|
|
||||||
|
|
||||||
def test_more_complex_instances():
|
def test_more_complex_instances():
|
||||||
|
|||||||
Reference in New Issue
Block a user