Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF057.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@
round(
17 # a comment
)

# See: https://github.com/astral-sh/ruff/issues/21209
print(round(125, **{"ndigits": -2}))
print(round(125, *[-2]))
9 changes: 9 additions & 0 deletions crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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