mirror of https://github.com/astral-sh/ruff
[`refurb`] Fix false positive for float and complex numbers in `FURB116` (#17661)
This commit is contained in:
parent
b7d0b3f9e5
commit
097af060c9
|
|
@ -17,3 +17,8 @@ print(bin(int(f"{num}"))[2:]) # FURB116 (no autofix)
|
||||||
## invalid
|
## invalid
|
||||||
print(oct(0o1337)[1:])
|
print(oct(0o1337)[1:])
|
||||||
print(hex(0x1337)[3:])
|
print(hex(0x1337)[3:])
|
||||||
|
|
||||||
|
# https://github.com/astral-sh/ruff/issues/16472
|
||||||
|
# float and complex numbers should be ignored
|
||||||
|
print(bin(1.0)[2:])
|
||||||
|
print(bin(3.14j)[2:])
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
||||||
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
||||||
use ruff_python_ast::{self as ast, Expr, ExprCall};
|
use ruff_python_ast::{self as ast, Expr, ExprCall, Number};
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
|
|
@ -110,6 +110,17 @@ pub(crate) fn fstring_number_format(checker: &Checker, subscript: &ast::ExprSubs
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// float and complex numbers are false positives, ignore them.
|
||||||
|
if matches!(
|
||||||
|
arg,
|
||||||
|
Expr::NumberLiteral(ast::ExprNumberLiteral {
|
||||||
|
value: Number::Float(_) | Number::Complex { .. },
|
||||||
|
..
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Generate a replacement, if possible.
|
// Generate a replacement, if possible.
|
||||||
let replacement = if matches!(
|
let replacement = if matches!(
|
||||||
arg,
|
arg,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue