mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[refurb
] Fix false positive for float and complex numbers in FURB116
(#17661)
This commit is contained in:
parent
b7d0b3f9e5
commit
097af060c9
2 changed files with 17 additions and 1 deletions
|
@ -17,3 +17,8 @@ print(bin(int(f"{num}"))[2:]) # FURB116 (no autofix)
|
|||
## invalid
|
||||
print(oct(0o1337)[1:])
|
||||
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_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 crate::checkers::ast::Checker;
|
||||
|
@ -110,6 +110,17 @@ pub(crate) fn fstring_number_format(checker: &Checker, subscript: &ast::ExprSubs
|
|||
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.
|
||||
let replacement = if matches!(
|
||||
arg,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue