Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pylint] Recode nan-comparison rule to W0177 #10894

Merged
merged 1 commit into from
Apr 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.