Fix keyword argument completion, fixes #1856

This commit is contained in:
Dave Halter
2022-11-13 20:26:00 +01:00
parent b0d5fc2bd0
commit 3a30008cc4
2 changed files with 16 additions and 1 deletions

View File

@@ -280,7 +280,7 @@ class CallDetails:
def count_positional_arguments(self):
count = 0
for star_count, key_start, had_equal in self._list_arguments()[:-1]:
if star_count:
if star_count or key_start:
break
count += 1
return count

View File

@@ -739,3 +739,18 @@ def test_param_infer_default():
param, = abs_sig.params
assert param.name == 'x'
assert param.infer_default() == []
@pytest.mark.parametrize(
'code, expected', [
("random.triangular(", ['high=', 'low=', 'mode=']),
("random.triangular(low=1, ", ['high=', 'mode=']),
("random.triangular(high=1, ", ['low=', 'mode=']),
("random.triangular(low=1, high=2, ", ['mode=']),
("random.triangular(low=1, mode=2, ", ['high=']),
],
)
def test_keyword_param_completion(code, expected):
import random
completions = jedi.Interpreter(code, [locals()]).complete()
assert expected == [c.name for c in completions if c.name.endswith('=')]