Check for keyword arguments before the last star argument (#1420)

This commit is contained in:
Anders Kaseorg 2022-12-27 20:20:03 -08:00 committed by GitHub
parent 1822b57ed5
commit a8cde5a936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View File

@ -5,9 +5,11 @@ def f(*args, **kwargs):
a = (1, 2)
b = (3, 4)
c = (5, 6)
d = (7, 8)
f(a, b)
f(a, kw=b)
f(*a, kw=b)
f(kw=a, *b)
f(kw=a, *b, *c)
f(*a, kw=b, *c, kw1=d)

View File

@ -1686,7 +1686,7 @@ pub fn keyword_argument_before_star_argument(args: &[Expr], keywords: &[Keyword]
let mut checks = vec![];
if let Some(arg) = args
.iter()
.find(|arg| matches!(arg.node, ExprKind::Starred { .. }))
.rfind(|arg| matches!(arg.node, ExprKind::Starred { .. }))
{
for keyword in keywords {
if keyword.location < arg.location {

View File

@ -5,19 +5,28 @@ expression: checks
- kind:
KeywordArgumentBeforeStarArgument: kw
location:
row: 12
row: 13
column: 2
end_location:
row: 12
row: 13
column: 6
fix: ~
- kind:
KeywordArgumentBeforeStarArgument: kw
location:
row: 13
row: 14
column: 2
end_location:
row: 13
row: 14
column: 6
fix: ~
- kind:
KeywordArgumentBeforeStarArgument: kw
location:
row: 15
column: 6
end_location:
row: 15
column: 10
fix: ~