Skip to content

Commit 826b2c9

Browse files
authored
[pycodestyle] Fix duplicated diagnostic in E712 (#17651)
1 parent a3e55cf commit 826b2c9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

crates/ruff_linter/resources/test/fixtures/pycodestyle/E712.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@
5353
assert (not foo) in bar
5454
assert {"x": not foo} in bar
5555
assert [42, not foo] in bar
56+
57+
# https://github.com/astral-sh/ruff/issues/17582
58+
if True == True: # No duplicated diagnostic
59+
pass

crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ pub(crate) fn literal_comparisons(checker: &Checker, compare: &ast::ExprCompare)
311311
if let Expr::BooleanLiteral(ast::ExprBooleanLiteral { value, .. }) = next {
312312
match op {
313313
EqCmpOp::Eq => {
314+
if let Expr::BooleanLiteral(ast::ExprBooleanLiteral {
315+
value: comparator_value,
316+
..
317+
}) = comparator
318+
{
319+
if value == comparator_value {
320+
continue;
321+
}
322+
}
323+
314324
let cond = if compare.ops.len() == 1 {
315325
Some(SourceCodeSnippet::from_str(
316326
checker.locator().slice(comparator),

crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E712_E712.py.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,20 @@ E712.py:31:4: E712 [*] Avoid equality comparisons to `True`; use `if yield i:` f
265265
32 32 | print("even")
266266
33 33 |
267267
34 34 | #: Okay
268+
269+
E712.py:58:4: E712 [*] Avoid equality comparisons to `True`; use `if True:` for truth checks
270+
|
271+
57 | # https://github.com/astral-sh/ruff/issues/17582
272+
58 | if True == True: # No duplicated diagnostic
273+
| ^^^^^^^^^^^^ E712
274+
59 | pass
275+
|
276+
= help: Replace with `True`
277+
278+
Unsafe fix
279+
55 55 | assert [42, not foo] in bar
280+
56 56 |
281+
57 57 | # https://github.com/astral-sh/ruff/issues/17582
282+
58 |-if True == True: # No duplicated diagnostic
283+
58 |+if True: # No duplicated diagnostic
284+
59 59 | pass

0 commit comments

Comments
 (0)