[`ruff`] Fix false positives on starred arguments (`RUF057`) (#21256)

## Summary

Fixes https://github.com/astral-sh/ruff/issues/21209

## Test Plan

`cargo nextest run ruf057`
This commit is contained in:
chiri 2025-11-05 20:07:33 +03:00 committed by GitHub
parent 5c69e00d1c
commit cef6600cf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View File

@ -81,3 +81,7 @@ round(# a comment
round(
17 # a comment
)
# See: https://github.com/astral-sh/ruff/issues/21209
print(round(125, **{"ndigits": -2}))
print(round(125, *[-2]))

View File

@ -143,6 +143,15 @@ pub(super) fn rounded_and_ndigits<'a>(
return None;
}
// *args
if arguments.args.iter().any(Expr::is_starred_expr) {
return None;
}
// **kwargs
if arguments.keywords.iter().any(|kw| kw.arg.is_none()) {
return None;
}
let rounded = arguments.find_argument_value("number", 0)?;
let ndigits = arguments.find_argument_value("ndigits", 1);

View File

@ -253,6 +253,8 @@ RUF057 [*] Value being rounded is already an integer
82 | | 17 # a comment
83 | | )
| |_^
84 |
85 | # See: https://github.com/astral-sh/ruff/issues/21209
|
help: Remove unnecessary `round` call
78 | round(# a comment
@ -262,4 +264,7 @@ help: Remove unnecessary `round` call
- 17 # a comment
- )
81 + 17
82 |
83 | # See: https://github.com/astral-sh/ruff/issues/21209
84 | print(round(125, **{"ndigits": -2}))
note: This is an unsafe fix and may change runtime behavior