[ruff] Avoid reporting when ndigits is possibly negative (RUF057) (#15234)

This commit is contained in:
InSync 2025-01-04 01:48:03 +07:00 committed by GitHub
parent 75015b0ed9
commit 842f882ef0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 151 additions and 295 deletions

View file

@ -6,14 +6,16 @@ inferred_float = 1.
round(42) # Error (safe) round(42) # Error (safe)
round(42, None) # Error (safe) round(42, None) # Error (safe)
round(42, 2) # Error (safe) round(42, 2) # Error (safe)
round(42, inferred_int) # Error (safe) round(42, -2) # No error
round(42, 3 + 4) # Error (safe) round(42, inferred_int) # No error
round(42, foo) # Error (unsafe) round(42, 3 + 4) # No error
round(42, foo) # No error
round(42.) # No error round(42.) # No error
round(42., None) # No error round(42., None) # No error
round(42., 2) # No error round(42., 2) # No error
round(42., -2) # No error
round(42., inferred_int) # No error round(42., inferred_int) # No error
round(42., 3 + 4) # No error round(42., 3 + 4) # No error
round(42., foo) # No error round(42., foo) # No error
@ -22,14 +24,16 @@ round(42., foo) # No error
round(4 + 2) # Error (safe) round(4 + 2) # Error (safe)
round(4 + 2, None) # Error (safe) round(4 + 2, None) # Error (safe)
round(4 + 2, 2) # Error (safe) round(4 + 2, 2) # Error (safe)
round(4 + 2, inferred_int) # Error (safe) round(4 + 2, -2) # No error
round(4 + 2, 3 + 4) # Error (safe) round(4 + 2, inferred_int) # No error
round(4 + 2, foo) # Error (unsafe) round(4 + 2, 3 + 4) # No error
round(4 + 2, foo) # No error
round(4. + 2.) # No error round(4. + 2.) # No error
round(4. + 2., None) # No error round(4. + 2., None) # No error
round(4. + 2., 2) # No error round(4. + 2., 2) # No error
round(4. + 2., -2) # No error
round(4. + 2., inferred_int) # No error round(4. + 2., inferred_int) # No error
round(4. + 2., 3 + 4) # No error round(4. + 2., 3 + 4) # No error
round(4. + 2., foo) # No error round(4. + 2., foo) # No error
@ -38,14 +42,16 @@ round(4. + 2., foo) # No error
round(inferred_int) # Error (unsafe) round(inferred_int) # Error (unsafe)
round(inferred_int, None) # Error (unsafe) round(inferred_int, None) # Error (unsafe)
round(inferred_int, 2) # Error (unsafe) round(inferred_int, 2) # Error (unsafe)
round(inferred_int, inferred_int) # Error (unsafe) round(inferred_int, -2) # No error
round(inferred_int, 3 + 4) # Error (unsafe) round(inferred_int, inferred_int) # No error
round(inferred_int, 3 + 4) # No error
round(inferred_int, foo) # No error round(inferred_int, foo) # No error
round(inferred_float) # No error round(inferred_float) # No error
round(inferred_float, None) # No error round(inferred_float, None) # No error
round(inferred_float, 2) # No error round(inferred_float, 2) # No error
round(inferred_float, -2) # No error
round(inferred_float, inferred_int) # No error round(inferred_float, inferred_int) # No error
round(inferred_float, 3 + 4) # No error round(inferred_float, 3 + 4) # No error
round(inferred_float, foo) # No error round(inferred_float, foo) # No error
@ -54,6 +60,7 @@ round(inferred_float, foo) # No error
round(lorem) # No error round(lorem) # No error
round(lorem, None) # No error round(lorem, None) # No error
round(lorem, 2) # No error round(lorem, 2) # No error
round(lorem, -2) # No error
round(lorem, inferred_int) # No error round(lorem, inferred_int) # No error
round(lorem, 3 + 4) # No error round(lorem, 3 + 4) # No error
round(lorem, foo) # No error round(lorem, foo) # No error

View file

@ -179,37 +179,38 @@ fn round_applicability(arguments: &Arguments, semantic: &SemanticModel) -> Optio
match (rounded_value, ndigits_value) { match (rounded_value, ndigits_value) {
// ```python // ```python
// int(round(2, -1))
// int(round(2, 0)) // int(round(2, 0))
// int(round(2)) // int(round(2))
// int(round(2, None)) // int(round(2, None))
// ``` // ```
( (
RoundedValue::Int(InferredType::Equivalent), RoundedValue::Int(InferredType::Equivalent),
NdigitsValue::Int(InferredType::Equivalent) NdigitsValue::LiteralInt { .. }
| NdigitsValue::NotGiven | NdigitsValue::Int(InferredType::Equivalent)
| NdigitsValue::LiteralNone, | NdigitsValue::NotGivenOrNone,
) => Some(Applicability::Safe), ) => Some(Applicability::Safe),
// ```python // ```python
// int(round(2.0)) // int(round(2.0))
// int(round(2.0, None)) // int(round(2.0, None))
// ``` // ```
( (RoundedValue::Float(InferredType::Equivalent), NdigitsValue::NotGivenOrNone) => {
RoundedValue::Float(InferredType::Equivalent), Some(Applicability::Safe)
NdigitsValue::NotGiven | NdigitsValue::LiteralNone, }
) => Some(Applicability::Safe),
// ```python // ```python
// a: int = 2 # or True // a: int = 2 # or True
// int(round(a, -2))
// int(round(a, 1)) // int(round(a, 1))
// int(round(a)) // int(round(a))
// int(round(a, None)) // int(round(a, None))
// ``` // ```
( (
RoundedValue::Int(InferredType::AssignableTo), RoundedValue::Int(InferredType::AssignableTo),
NdigitsValue::Int(InferredType::Equivalent) NdigitsValue::LiteralInt { .. }
| NdigitsValue::NotGiven | NdigitsValue::Int(InferredType::Equivalent)
| NdigitsValue::LiteralNone, | NdigitsValue::NotGivenOrNone,
) => Some(Applicability::Unsafe), ) => Some(Applicability::Unsafe),
// ```python // ```python
@ -220,7 +221,7 @@ fn round_applicability(arguments: &Arguments, semantic: &SemanticModel) -> Optio
// ``` // ```
( (
RoundedValue::Float(InferredType::AssignableTo) | RoundedValue::Other, RoundedValue::Float(InferredType::AssignableTo) | RoundedValue::Other,
NdigitsValue::NotGiven | NdigitsValue::LiteralNone, NdigitsValue::NotGivenOrNone,
) => Some(Applicability::Unsafe), ) => Some(Applicability::Unsafe),
_ => None, _ => None,

View file

@ -2,7 +2,7 @@ use crate::checkers::ast::Checker;
use crate::Locator; use crate::Locator;
use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix}; use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_ast::{Arguments, Expr, ExprCall}; use ruff_python_ast::{Arguments, Expr, ExprCall, ExprNumberLiteral, Number};
use ruff_python_semantic::analyze::type_inference::{NumberLike, PythonType, ResolvedPythonType}; use ruff_python_semantic::analyze::type_inference::{NumberLike, PythonType, ResolvedPythonType};
use ruff_python_semantic::analyze::typing; use ruff_python_semantic::analyze::typing;
use ruff_python_semantic::SemanticModel; use ruff_python_semantic::SemanticModel;
@ -52,14 +52,14 @@ pub(crate) fn unnecessary_round(checker: &mut Checker, call: &ExprCall) {
return; return;
}; };
let applicability = match (rounded_value, ndigits_value) { if !matches!(
// ```python ndigits_value,
// rounded(1, unknown) NdigitsValue::NotGivenOrNone | NdigitsValue::LiteralInt { is_negative: false }
// ``` ) {
(RoundedValue::Int(InferredType::Equivalent), NdigitsValue::Other) => Applicability::Unsafe, return;
}
(_, NdigitsValue::Other) => return,
let applicability = match rounded_value {
// ```python // ```python
// some_int: int // some_int: int
// //
@ -69,7 +69,7 @@ pub(crate) fn unnecessary_round(checker: &mut Checker, call: &ExprCall) {
// rounded(1, 4 + 2) // rounded(1, 4 + 2)
// rounded(1, some_int) // rounded(1, some_int)
// ``` // ```
(RoundedValue::Int(InferredType::Equivalent), _) => Applicability::Safe, RoundedValue::Int(InferredType::Equivalent) => Applicability::Safe,
// ```python // ```python
// some_int: int // some_int: int
@ -81,7 +81,7 @@ pub(crate) fn unnecessary_round(checker: &mut Checker, call: &ExprCall) {
// rounded(some_int, 4 + 2) // rounded(some_int, 4 + 2)
// rounded(some_int, some_other_int) // rounded(some_int, some_other_int)
// ``` // ```
(RoundedValue::Int(InferredType::AssignableTo), _) => Applicability::Unsafe, RoundedValue::Int(InferredType::AssignableTo) => Applicability::Unsafe,
_ => return, _ => return,
}; };
@ -113,8 +113,8 @@ pub(super) enum RoundedValue {
/// The type of the second argument to `round()` /// The type of the second argument to `round()`
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(super) enum NdigitsValue { pub(super) enum NdigitsValue {
NotGiven, NotGivenOrNone,
LiteralNone, LiteralInt { is_negative: bool },
Int(InferredType), Int(InferredType),
Other, Other,
} }
@ -157,8 +157,7 @@ pub(super) fn rounded_and_ndigits<'a>(
}; };
let ndigits_kind = match ndigits { let ndigits_kind = match ndigits {
None => NdigitsValue::NotGiven, None | Some(Expr::NoneLiteral(_)) => NdigitsValue::NotGivenOrNone,
Some(Expr::NoneLiteral(_)) => NdigitsValue::LiteralNone,
Some(Expr::Name(name)) => { Some(Expr::Name(name)) => {
match semantic.only_binding(name).map(|id| semantic.binding(id)) { match semantic.only_binding(name).map(|id| semantic.binding(id)) {
@ -169,6 +168,16 @@ pub(super) fn rounded_and_ndigits<'a>(
} }
} }
Some(Expr::NumberLiteral(ExprNumberLiteral {
value: Number::Int(int),
..
})) => match int.as_i64() {
None => NdigitsValue::Int(InferredType::Equivalent),
Some(value) => NdigitsValue::LiteralInt {
is_negative: value < 0,
},
},
Some(ndigits) => match ResolvedPythonType::from(ndigits) { Some(ndigits) => match ResolvedPythonType::from(ndigits) {
ResolvedPythonType::Atom(PythonType::Number(NumberLike::Integer)) => { ResolvedPythonType::Atom(PythonType::Number(NumberLike::Integer)) => {
NdigitsValue::Int(InferredType::Equivalent) NdigitsValue::Int(InferredType::Equivalent)

View file

@ -19,7 +19,7 @@ RUF057.py:6:1: RUF057 [*] Value being rounded is already an integer
6 |+42 # Error (safe) 6 |+42 # Error (safe)
7 7 | round(42, None) # Error (safe) 7 7 | round(42, None) # Error (safe)
8 8 | round(42, 2) # Error (safe) 8 8 | round(42, 2) # Error (safe)
9 9 | round(42, inferred_int) # Error (safe) 9 9 | round(42, -2) # No error
RUF057.py:7:1: RUF057 [*] Value being rounded is already an integer RUF057.py:7:1: RUF057 [*] Value being rounded is already an integer
| |
@ -27,7 +27,7 @@ RUF057.py:7:1: RUF057 [*] Value being rounded is already an integer
7 | round(42, None) # Error (safe) 7 | round(42, None) # Error (safe)
| ^^^^^^^^^^^^^^^ RUF057 | ^^^^^^^^^^^^^^^ RUF057
8 | round(42, 2) # Error (safe) 8 | round(42, 2) # Error (safe)
9 | round(42, inferred_int) # Error (safe) 9 | round(42, -2) # No error
| |
= help: Remove unnecessary `round` call = help: Remove unnecessary `round` call
@ -38,8 +38,8 @@ RUF057.py:7:1: RUF057 [*] Value being rounded is already an integer
7 |-round(42, None) # Error (safe) 7 |-round(42, None) # Error (safe)
7 |+42 # Error (safe) 7 |+42 # Error (safe)
8 8 | round(42, 2) # Error (safe) 8 8 | round(42, 2) # Error (safe)
9 9 | round(42, inferred_int) # Error (safe) 9 9 | round(42, -2) # No error
10 10 | round(42, 3 + 4) # Error (safe) 10 10 | round(42, inferred_int) # No error
RUF057.py:8:1: RUF057 [*] Value being rounded is already an integer RUF057.py:8:1: RUF057 [*] Value being rounded is already an integer
| |
@ -47,8 +47,8 @@ RUF057.py:8:1: RUF057 [*] Value being rounded is already an integer
7 | round(42, None) # Error (safe) 7 | round(42, None) # Error (safe)
8 | round(42, 2) # Error (safe) 8 | round(42, 2) # Error (safe)
| ^^^^^^^^^^^^ RUF057 | ^^^^^^^^^^^^ RUF057
9 | round(42, inferred_int) # Error (safe) 9 | round(42, -2) # No error
10 | round(42, 3 + 4) # Error (safe) 10 | round(42, inferred_int) # No error
| |
= help: Remove unnecessary `round` call = help: Remove unnecessary `round` call
@ -58,287 +58,126 @@ RUF057.py:8:1: RUF057 [*] Value being rounded is already an integer
7 7 | round(42, None) # Error (safe) 7 7 | round(42, None) # Error (safe)
8 |-round(42, 2) # Error (safe) 8 |-round(42, 2) # Error (safe)
8 |+42 # Error (safe) 8 |+42 # Error (safe)
9 9 | round(42, inferred_int) # Error (safe) 9 9 | round(42, -2) # No error
10 10 | round(42, 3 + 4) # Error (safe) 10 10 | round(42, inferred_int) # No error
11 11 | round(42, foo) # Error (unsafe) 11 11 | round(42, 3 + 4) # No error
RUF057.py:9:1: RUF057 [*] Value being rounded is already an integer
|
7 | round(42, None) # Error (safe)
8 | round(42, 2) # Error (safe)
9 | round(42, inferred_int) # Error (safe)
| ^^^^^^^^^^^^^^^^^^^^^^^ RUF057
10 | round(42, 3 + 4) # Error (safe)
11 | round(42, foo) # Error (unsafe)
|
= help: Remove unnecessary `round` call
Safe fix
6 6 | round(42) # Error (safe)
7 7 | round(42, None) # Error (safe)
8 8 | round(42, 2) # Error (safe)
9 |-round(42, inferred_int) # Error (safe)
9 |+42 # Error (safe)
10 10 | round(42, 3 + 4) # Error (safe)
11 11 | round(42, foo) # Error (unsafe)
12 12 |
RUF057.py:10:1: RUF057 [*] Value being rounded is already an integer
|
8 | round(42, 2) # Error (safe)
9 | round(42, inferred_int) # Error (safe)
10 | round(42, 3 + 4) # Error (safe)
| ^^^^^^^^^^^^^^^^ RUF057
11 | round(42, foo) # Error (unsafe)
|
= help: Remove unnecessary `round` call
Safe fix
7 7 | round(42, None) # Error (safe)
8 8 | round(42, 2) # Error (safe)
9 9 | round(42, inferred_int) # Error (safe)
10 |-round(42, 3 + 4) # Error (safe)
10 |+42 # Error (safe)
11 11 | round(42, foo) # Error (unsafe)
12 12 |
13 13 |
RUF057.py:11:1: RUF057 [*] Value being rounded is already an integer
|
9 | round(42, inferred_int) # Error (safe)
10 | round(42, 3 + 4) # Error (safe)
11 | round(42, foo) # Error (unsafe)
| ^^^^^^^^^^^^^^ RUF057
|
= help: Remove unnecessary `round` call
Unsafe fix
8 8 | round(42, 2) # Error (safe)
9 9 | round(42, inferred_int) # Error (safe)
10 10 | round(42, 3 + 4) # Error (safe)
11 |-round(42, foo) # Error (unsafe)
11 |+42 # Error (unsafe)
12 12 |
13 13 |
14 14 | round(42.) # No error
RUF057.py:22:1: RUF057 [*] Value being rounded is already an integer
|
22 | round(4 + 2) # Error (safe)
| ^^^^^^^^^^^^ RUF057
23 | round(4 + 2, None) # Error (safe)
24 | round(4 + 2, 2) # Error (safe)
|
= help: Remove unnecessary `round` call
Safe fix
19 19 | round(42., foo) # No error
20 20 |
21 21 |
22 |-round(4 + 2) # Error (safe)
22 |+4 + 2 # Error (safe)
23 23 | round(4 + 2, None) # Error (safe)
24 24 | round(4 + 2, 2) # Error (safe)
25 25 | round(4 + 2, inferred_int) # Error (safe)
RUF057.py:23:1: RUF057 [*] Value being rounded is already an integer
|
22 | round(4 + 2) # Error (safe)
23 | round(4 + 2, None) # Error (safe)
| ^^^^^^^^^^^^^^^^^^ RUF057
24 | round(4 + 2, 2) # Error (safe)
25 | round(4 + 2, inferred_int) # Error (safe)
|
= help: Remove unnecessary `round` call
Safe fix
20 20 |
21 21 |
22 22 | round(4 + 2) # Error (safe)
23 |-round(4 + 2, None) # Error (safe)
23 |+4 + 2 # Error (safe)
24 24 | round(4 + 2, 2) # Error (safe)
25 25 | round(4 + 2, inferred_int) # Error (safe)
26 26 | round(4 + 2, 3 + 4) # Error (safe)
RUF057.py:24:1: RUF057 [*] Value being rounded is already an integer RUF057.py:24:1: RUF057 [*] Value being rounded is already an integer
| |
22 | round(4 + 2) # Error (safe) 24 | round(4 + 2) # Error (safe)
23 | round(4 + 2, None) # Error (safe) | ^^^^^^^^^^^^ RUF057
24 | round(4 + 2, 2) # Error (safe) 25 | round(4 + 2, None) # Error (safe)
| ^^^^^^^^^^^^^^^ RUF057 26 | round(4 + 2, 2) # Error (safe)
25 | round(4 + 2, inferred_int) # Error (safe)
26 | round(4 + 2, 3 + 4) # Error (safe)
| |
= help: Remove unnecessary `round` call = help: Remove unnecessary `round` call
Safe fix Safe fix
21 21 | 21 21 | round(42., foo) # No error
22 22 | round(4 + 2) # Error (safe) 22 22 |
23 23 | round(4 + 2, None) # Error (safe) 23 23 |
24 |-round(4 + 2, 2) # Error (safe) 24 |-round(4 + 2) # Error (safe)
24 |+4 + 2 # Error (safe) 24 |+4 + 2 # Error (safe)
25 25 | round(4 + 2, inferred_int) # Error (safe) 25 25 | round(4 + 2, None) # Error (safe)
26 26 | round(4 + 2, 3 + 4) # Error (safe) 26 26 | round(4 + 2, 2) # Error (safe)
27 27 | round(4 + 2, foo) # Error (unsafe) 27 27 | round(4 + 2, -2) # No error
RUF057.py:25:1: RUF057 [*] Value being rounded is already an integer RUF057.py:25:1: RUF057 [*] Value being rounded is already an integer
| |
23 | round(4 + 2, None) # Error (safe) 24 | round(4 + 2) # Error (safe)
24 | round(4 + 2, 2) # Error (safe) 25 | round(4 + 2, None) # Error (safe)
25 | round(4 + 2, inferred_int) # Error (safe) | ^^^^^^^^^^^^^^^^^^ RUF057
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF057 26 | round(4 + 2, 2) # Error (safe)
26 | round(4 + 2, 3 + 4) # Error (safe) 27 | round(4 + 2, -2) # No error
27 | round(4 + 2, foo) # Error (unsafe)
| |
= help: Remove unnecessary `round` call = help: Remove unnecessary `round` call
Safe fix Safe fix
22 22 | round(4 + 2) # Error (safe) 22 22 |
23 23 | round(4 + 2, None) # Error (safe) 23 23 |
24 24 | round(4 + 2, 2) # Error (safe) 24 24 | round(4 + 2) # Error (safe)
25 |-round(4 + 2, inferred_int) # Error (safe) 25 |-round(4 + 2, None) # Error (safe)
25 |+4 + 2 # Error (safe) 25 |+4 + 2 # Error (safe)
26 26 | round(4 + 2, 3 + 4) # Error (safe) 26 26 | round(4 + 2, 2) # Error (safe)
27 27 | round(4 + 2, foo) # Error (unsafe) 27 27 | round(4 + 2, -2) # No error
28 28 | 28 28 | round(4 + 2, inferred_int) # No error
RUF057.py:26:1: RUF057 [*] Value being rounded is already an integer RUF057.py:26:1: RUF057 [*] Value being rounded is already an integer
| |
24 | round(4 + 2, 2) # Error (safe) 24 | round(4 + 2) # Error (safe)
25 | round(4 + 2, inferred_int) # Error (safe) 25 | round(4 + 2, None) # Error (safe)
26 | round(4 + 2, 3 + 4) # Error (safe) 26 | round(4 + 2, 2) # Error (safe)
| ^^^^^^^^^^^^^^^^^^^ RUF057 | ^^^^^^^^^^^^^^^ RUF057
27 | round(4 + 2, foo) # Error (unsafe) 27 | round(4 + 2, -2) # No error
28 | round(4 + 2, inferred_int) # No error
| |
= help: Remove unnecessary `round` call = help: Remove unnecessary `round` call
Safe fix Safe fix
23 23 | round(4 + 2, None) # Error (safe) 23 23 |
24 24 | round(4 + 2, 2) # Error (safe) 24 24 | round(4 + 2) # Error (safe)
25 25 | round(4 + 2, inferred_int) # Error (safe) 25 25 | round(4 + 2, None) # Error (safe)
26 |-round(4 + 2, 3 + 4) # Error (safe) 26 |-round(4 + 2, 2) # Error (safe)
26 |+4 + 2 # Error (safe) 26 |+4 + 2 # Error (safe)
27 27 | round(4 + 2, foo) # Error (unsafe) 27 27 | round(4 + 2, -2) # No error
28 28 | 28 28 | round(4 + 2, inferred_int) # No error
29 29 | 29 29 | round(4 + 2, 3 + 4) # No error
RUF057.py:27:1: RUF057 [*] Value being rounded is already an integer
|
25 | round(4 + 2, inferred_int) # Error (safe)
26 | round(4 + 2, 3 + 4) # Error (safe)
27 | round(4 + 2, foo) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^ RUF057
|
= help: Remove unnecessary `round` call
Unsafe fix
24 24 | round(4 + 2, 2) # Error (safe)
25 25 | round(4 + 2, inferred_int) # Error (safe)
26 26 | round(4 + 2, 3 + 4) # Error (safe)
27 |-round(4 + 2, foo) # Error (unsafe)
27 |+4 + 2 # Error (unsafe)
28 28 |
29 29 |
30 30 | round(4. + 2.) # No error
RUF057.py:38:1: RUF057 [*] Value being rounded is already an integer
|
38 | round(inferred_int) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^ RUF057
39 | round(inferred_int, None) # Error (unsafe)
40 | round(inferred_int, 2) # Error (unsafe)
|
= help: Remove unnecessary `round` call
Unsafe fix
35 35 | round(4. + 2., foo) # No error
36 36 |
37 37 |
38 |-round(inferred_int) # Error (unsafe)
38 |+inferred_int # Error (unsafe)
39 39 | round(inferred_int, None) # Error (unsafe)
40 40 | round(inferred_int, 2) # Error (unsafe)
41 41 | round(inferred_int, inferred_int) # Error (unsafe)
RUF057.py:39:1: RUF057 [*] Value being rounded is already an integer
|
38 | round(inferred_int) # Error (unsafe)
39 | round(inferred_int, None) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^^^^^^^ RUF057
40 | round(inferred_int, 2) # Error (unsafe)
41 | round(inferred_int, inferred_int) # Error (unsafe)
|
= help: Remove unnecessary `round` call
Unsafe fix
36 36 |
37 37 |
38 38 | round(inferred_int) # Error (unsafe)
39 |-round(inferred_int, None) # Error (unsafe)
39 |+inferred_int # Error (unsafe)
40 40 | round(inferred_int, 2) # Error (unsafe)
41 41 | round(inferred_int, inferred_int) # Error (unsafe)
42 42 | round(inferred_int, 3 + 4) # Error (unsafe)
RUF057.py:40:1: RUF057 [*] Value being rounded is already an integer
|
38 | round(inferred_int) # Error (unsafe)
39 | round(inferred_int, None) # Error (unsafe)
40 | round(inferred_int, 2) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^^^^ RUF057
41 | round(inferred_int, inferred_int) # Error (unsafe)
42 | round(inferred_int, 3 + 4) # Error (unsafe)
|
= help: Remove unnecessary `round` call
Unsafe fix
37 37 |
38 38 | round(inferred_int) # Error (unsafe)
39 39 | round(inferred_int, None) # Error (unsafe)
40 |-round(inferred_int, 2) # Error (unsafe)
40 |+inferred_int # Error (unsafe)
41 41 | round(inferred_int, inferred_int) # Error (unsafe)
42 42 | round(inferred_int, 3 + 4) # Error (unsafe)
43 43 | round(inferred_int, foo) # No error
RUF057.py:41:1: RUF057 [*] Value being rounded is already an integer
|
39 | round(inferred_int, None) # Error (unsafe)
40 | round(inferred_int, 2) # Error (unsafe)
41 | round(inferred_int, inferred_int) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF057
42 | round(inferred_int, 3 + 4) # Error (unsafe)
43 | round(inferred_int, foo) # No error
|
= help: Remove unnecessary `round` call
Unsafe fix
38 38 | round(inferred_int) # Error (unsafe)
39 39 | round(inferred_int, None) # Error (unsafe)
40 40 | round(inferred_int, 2) # Error (unsafe)
41 |-round(inferred_int, inferred_int) # Error (unsafe)
41 |+inferred_int # Error (unsafe)
42 42 | round(inferred_int, 3 + 4) # Error (unsafe)
43 43 | round(inferred_int, foo) # No error
44 44 |
RUF057.py:42:1: RUF057 [*] Value being rounded is already an integer RUF057.py:42:1: RUF057 [*] Value being rounded is already an integer
| |
40 | round(inferred_int, 2) # Error (unsafe) 42 | round(inferred_int) # Error (unsafe)
41 | round(inferred_int, inferred_int) # Error (unsafe) | ^^^^^^^^^^^^^^^^^^^ RUF057
42 | round(inferred_int, 3 + 4) # Error (unsafe) 43 | round(inferred_int, None) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF057 44 | round(inferred_int, 2) # Error (unsafe)
43 | round(inferred_int, foo) # No error
| |
= help: Remove unnecessary `round` call = help: Remove unnecessary `round` call
Unsafe fix Unsafe fix
39 39 | round(inferred_int, None) # Error (unsafe) 39 39 | round(4. + 2., foo) # No error
40 40 | round(inferred_int, 2) # Error (unsafe) 40 40 |
41 41 | round(inferred_int, inferred_int) # Error (unsafe) 41 41 |
42 |-round(inferred_int, 3 + 4) # Error (unsafe) 42 |-round(inferred_int) # Error (unsafe)
42 |+inferred_int # Error (unsafe) 42 |+inferred_int # Error (unsafe)
43 43 | round(inferred_int, foo) # No error 43 43 | round(inferred_int, None) # Error (unsafe)
44 44 | 44 44 | round(inferred_int, 2) # Error (unsafe)
45 45 | 45 45 | round(inferred_int, -2) # No error
RUF057.py:43:1: RUF057 [*] Value being rounded is already an integer
|
42 | round(inferred_int) # Error (unsafe)
43 | round(inferred_int, None) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^^^^^^^ RUF057
44 | round(inferred_int, 2) # Error (unsafe)
45 | round(inferred_int, -2) # No error
|
= help: Remove unnecessary `round` call
Unsafe fix
40 40 |
41 41 |
42 42 | round(inferred_int) # Error (unsafe)
43 |-round(inferred_int, None) # Error (unsafe)
43 |+inferred_int # Error (unsafe)
44 44 | round(inferred_int, 2) # Error (unsafe)
45 45 | round(inferred_int, -2) # No error
46 46 | round(inferred_int, inferred_int) # No error
RUF057.py:44:1: RUF057 [*] Value being rounded is already an integer
|
42 | round(inferred_int) # Error (unsafe)
43 | round(inferred_int, None) # Error (unsafe)
44 | round(inferred_int, 2) # Error (unsafe)
| ^^^^^^^^^^^^^^^^^^^^^^ RUF057
45 | round(inferred_int, -2) # No error
46 | round(inferred_int, inferred_int) # No error
|
= help: Remove unnecessary `round` call
Unsafe fix
41 41 |
42 42 | round(inferred_int) # Error (unsafe)
43 43 | round(inferred_int, None) # Error (unsafe)
44 |-round(inferred_int, 2) # Error (unsafe)
44 |+inferred_int # Error (unsafe)
45 45 | round(inferred_int, -2) # No error
46 46 | round(inferred_int, inferred_int) # No error
47 47 | round(inferred_int, 3 + 4) # No error