Skip to content

Commit 5a5d3b0

Browse files
authored
[ruff] Ignore std cmath.inf (RUF069) (#23120)
## Summary See: #20585 ## Test Plan `cargo nextest run ruf069`
1 parent a1271fb commit 5a5d3b0

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

crates/ruff_linter/resources/test/fixtures/ruff/RUF069.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ def _numpy_torch():
7777
assert numpy_inf == 1e300 * 1e300 # ok
7878

7979
assert torch_inf == 1e300 * 1e300 # ok
80+
81+
82+
def _cmath():
83+
import cmath
84+
85+
assert cmath.inf == 1e300 * 1e300 # ok
86+
87+
assert cmath.infj == complex(0, 1e300 * 1e300) # ok

crates/ruff_linter/src/rules/ruff/rules/float_equality_comparison.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,14 @@ fn should_skip_comparison(expr: &Expr, semantic: &SemanticModel) -> bool {
218218
false
219219
}
220220

221-
// Skip `inf` when imported from `math`, `numpy` or `torch`
221+
// Skip `inf` when imported from `math`, `cmath`, `numpy` or `torch`
222+
// and `infj` from `cmath`
222223
_ => semantic
223224
.resolve_qualified_name(expr)
224225
.is_some_and(|qualified_name| {
225226
matches!(
226227
qualified_name.segments(),
227-
["math" | "numpy" | "torch", "inf"]
228+
["math" | "numpy" | "torch", "inf"] | ["cmath", "inf" | "infj"]
228229
)
229230
}),
230231
}

0 commit comments

Comments
 (0)