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
5 changes: 5 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/refurb/FURB116.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ def return_num() -> int:
## 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:])
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading