Skip to content

Commit 2e5fcfe

Browse files
charliermarshGlyphack
authored andcommitted
[pylint] Recode nan-comparison rule to W0177 (astral-sh#10894)
## Summary This was accidentally committed under `W0117`, but the actual Pylint code is `W0177`: https://pylint.readthedocs.io/en/latest/user_guide/checkers/features.html. Closes astral-sh#10791.
1 parent d8ae32e commit 2e5fcfe

6 files changed

+88
-86
lines changed

crates/ruff_linter/src/codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
297297
#[allow(deprecated)]
298298
(Pylint, "R6301") => (RuleGroup::Nursery, rules::pylint::rules::NoSelfUse),
299299
(Pylint, "W0108") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryLambda),
300-
(Pylint, "W0117") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
300+
(Pylint, "W0177") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
301301
(Pylint, "W0120") => (RuleGroup::Stable, rules::pylint::rules::UselessElseOnLoop),
302302
(Pylint, "W0127") => (RuleGroup::Stable, rules::pylint::rules::SelfAssigningVariable),
303303
(Pylint, "W0128") => (RuleGroup::Preview, rules::pylint::rules::RedeclaredAssignedName),

crates/ruff_linter/src/rule_redirects.rs

+2
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
109109
// Test redirect by prefix
110110
#[cfg(feature = "test-rules")]
111111
("RUF96", "RUF95"),
112+
// See: https://github.com/astral-sh/ruff/issues/10791
113+
("PLW0117", "PLW0177"),
112114
])
113115
});

crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Violation for NanComparison {
4747
}
4848
}
4949

50-
/// PLW0117
50+
/// PLW0177
5151
pub(crate) fn nan_comparison(checker: &mut Checker, left: &Expr, comparators: &[Expr]) {
5252
for expr in std::iter::once(left).chain(comparators.iter()) {
5353
if let Some(qualified_name) = checker.semantic().resolve_qualified_name(expr) {

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW0117_nan_comparison.py.snap

-82
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
source: crates/ruff_linter/src/rules/pylint/mod.rs
3+
---
4+
nan_comparison.py:11:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
5+
|
6+
10 | # PLW0117
7+
11 | if x == float("nan"):
8+
| ^^^^^^^^^^^^ PLW0177
9+
12 | pass
10+
|
11+
12+
nan_comparison.py:15:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
13+
|
14+
14 | # PLW0117
15+
15 | if x == float("NaN"):
16+
| ^^^^^^^^^^^^ PLW0177
17+
16 | pass
18+
|
19+
20+
nan_comparison.py:19:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
21+
|
22+
18 | # PLW0117
23+
19 | if x == float("NAN"):
24+
| ^^^^^^^^^^^^ PLW0177
25+
20 | pass
26+
|
27+
28+
nan_comparison.py:23:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
29+
|
30+
22 | # PLW0117
31+
23 | if x == float("Nan"):
32+
| ^^^^^^^^^^^^ PLW0177
33+
24 | pass
34+
|
35+
36+
nan_comparison.py:27:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
37+
|
38+
26 | # PLW0117
39+
27 | if x == math.nan:
40+
| ^^^^^^^^ PLW0177
41+
28 | pass
42+
|
43+
44+
nan_comparison.py:31:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
45+
|
46+
30 | # PLW0117
47+
31 | if x == bad_val:
48+
| ^^^^^^^ PLW0177
49+
32 | pass
50+
|
51+
52+
nan_comparison.py:35:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
53+
|
54+
34 | # PLW0117
55+
35 | if y == np.NaN:
56+
| ^^^^^^ PLW0177
57+
36 | pass
58+
|
59+
60+
nan_comparison.py:39:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
61+
|
62+
38 | # PLW0117
63+
39 | if y == np.NAN:
64+
| ^^^^^^ PLW0177
65+
40 | pass
66+
|
67+
68+
nan_comparison.py:43:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
69+
|
70+
42 | # PLW0117
71+
43 | if y == np.nan:
72+
| ^^^^^^ PLW0177
73+
44 | pass
74+
|
75+
76+
nan_comparison.py:47:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
77+
|
78+
46 | # PLW0117
79+
47 | if y == npy_nan:
80+
| ^^^^^^^ PLW0177
81+
48 | pass
82+
|

ruff.schema.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)