Skip to content

Commit

Permalink
[pylint] Recode nan-comparison rule to W0177 (#10894)
Browse files Browse the repository at this point in the history
## 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 #10791.
  • Loading branch information
charliermarsh authored Apr 12, 2024
1 parent 563daa8 commit 312f434
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
#[allow(deprecated)]
(Pylint, "R6301") => (RuleGroup::Nursery, rules::pylint::rules::NoSelfUse),
(Pylint, "W0108") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryLambda),
(Pylint, "W0117") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
(Pylint, "W0177") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
(Pylint, "W0120") => (RuleGroup::Stable, rules::pylint::rules::UselessElseOnLoop),
(Pylint, "W0127") => (RuleGroup::Stable, rules::pylint::rules::SelfAssigningVariable),
(Pylint, "W0128") => (RuleGroup::Preview, rules::pylint::rules::RedeclaredAssignedName),
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/rule_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
// Test redirect by prefix
#[cfg(feature = "test-rules")]
("RUF96", "RUF95"),
// See: https://github.com/astral-sh/ruff/issues/10791
("PLW0117", "PLW0177"),
])
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Violation for NanComparison {
}
}

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
nan_comparison.py:11:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
|
10 | # PLW0117
11 | if x == float("nan"):
| ^^^^^^^^^^^^ PLW0177
12 | pass
|

nan_comparison.py:15:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
|
14 | # PLW0117
15 | if x == float("NaN"):
| ^^^^^^^^^^^^ PLW0177
16 | pass
|

nan_comparison.py:19:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
|
18 | # PLW0117
19 | if x == float("NAN"):
| ^^^^^^^^^^^^ PLW0177
20 | pass
|

nan_comparison.py:23:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
|
22 | # PLW0117
23 | if x == float("Nan"):
| ^^^^^^^^^^^^ PLW0177
24 | pass
|

nan_comparison.py:27:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
|
26 | # PLW0117
27 | if x == math.nan:
| ^^^^^^^^ PLW0177
28 | pass
|

nan_comparison.py:31:9: PLW0177 Comparing against a NaN value; use `math.isnan` instead
|
30 | # PLW0117
31 | if x == bad_val:
| ^^^^^^^ PLW0177
32 | pass
|

nan_comparison.py:35:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
|
34 | # PLW0117
35 | if y == np.NaN:
| ^^^^^^ PLW0177
36 | pass
|

nan_comparison.py:39:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
|
38 | # PLW0117
39 | if y == np.NAN:
| ^^^^^^ PLW0177
40 | pass
|

nan_comparison.py:43:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
|
42 | # PLW0117
43 | if y == np.nan:
| ^^^^^^ PLW0177
44 | pass
|

nan_comparison.py:47:9: PLW0177 Comparing against a NaN value; use `np.isnan` instead
|
46 | # PLW0117
47 | if y == npy_nan:
| ^^^^^^^ PLW0177
48 | pass
|
4 changes: 2 additions & 2 deletions ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 312f434

Please sign in to comment.