Show which keyword argument is repeated on 3.9+

This commit is contained in:
Batuhan Taskaya
2020-05-23 14:06:24 +03:00
parent 8bb211fafb
commit 216a77dce5
2 changed files with 9 additions and 2 deletions

View File

@@ -817,7 +817,10 @@ class _ArglistRule(SyntaxRule):
if first.type == 'name':
if first.value in arg_set:
# f(x=1, x=2)
self.add_issue(first, message="keyword argument repeated")
message = "keyword argument repeated"
if self._normalizer.version >= (3, 9):
message += ": {}".format(first.value)
self.add_issue(first, message=message)
else:
arg_set.add(first.value)
else:

View File

@@ -359,6 +359,10 @@ def test_continue_in_finally():
]
)
def test_forbidden_name(template, target):
assert _get_error_list(template.format(target=target), version="3")[0].message
assert _get_error_list(template.format(target=target), version="3")
def test_repeated_kwarg():
# python 3.9+ shows which argument is repeated
assert "q" not in _get_error_list("f(q=1, q=2)", version="3.8")[0].message
assert "q" in _get_error_list("f(q=1, q=2)", version="3.9")[0].message