diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF057.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF057.py index 2db91ac322..bb43b6d1d4 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF057.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF057.py @@ -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])) \ No newline at end of file diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs index c7fe4687e8..e2ab51e1db 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs @@ -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); diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF057_RUF057.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF057_RUF057.py.snap index abace6c8b4..8c536b67a8 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF057_RUF057.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF057_RUF057.py.snap @@ -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