mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[pycodestyle] Make E712
suggestion not assume a context (#18328)
This commit is contained in:
parent
3eada01153
commit
602dd5c039
3 changed files with 18 additions and 22 deletions
|
@ -136,22 +136,18 @@ impl AlwaysFixableViolation for TrueFalseComparison {
|
|||
let cond = cond.truncated_display();
|
||||
match (value, op) {
|
||||
(true, EqCmpOp::Eq) => {
|
||||
format!("Avoid equality comparisons to `True`; use `if {cond}:` for truth checks")
|
||||
format!("Avoid equality comparisons to `True`; use `{cond}:` for truth checks")
|
||||
}
|
||||
(true, EqCmpOp::NotEq) => {
|
||||
format!(
|
||||
"Avoid inequality comparisons to `True`; use `if not {cond}:` for false checks"
|
||||
"Avoid inequality comparisons to `True`; use `not {cond}:` for false checks"
|
||||
)
|
||||
}
|
||||
(false, EqCmpOp::Eq) => {
|
||||
format!(
|
||||
"Avoid equality comparisons to `False`; use `if not {cond}:` for false checks"
|
||||
)
|
||||
format!("Avoid equality comparisons to `False`; use `not {cond}:` for false checks")
|
||||
}
|
||||
(false, EqCmpOp::NotEq) => {
|
||||
format!(
|
||||
"Avoid inequality comparisons to `False`; use `if {cond}:` for truth checks"
|
||||
)
|
||||
format!("Avoid inequality comparisons to `False`; use `{cond}:` for truth checks")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
|
||||
---
|
||||
E712.py:2:4: E712 [*] Avoid equality comparisons to `True`; use `if res:` for truth checks
|
||||
E712.py:2:4: E712 [*] Avoid equality comparisons to `True`; use `res:` for truth checks
|
||||
|
|
||||
1 | #: E712
|
||||
2 | if res == True:
|
||||
|
@ -19,7 +19,7 @@ E712.py:2:4: E712 [*] Avoid equality comparisons to `True`; use `if res:` for tr
|
|||
4 4 | #: E712
|
||||
5 5 | if res != False:
|
||||
|
||||
E712.py:5:4: E712 [*] Avoid inequality comparisons to `False`; use `if res:` for truth checks
|
||||
E712.py:5:4: E712 [*] Avoid inequality comparisons to `False`; use `res:` for truth checks
|
||||
|
|
||||
3 | pass
|
||||
4 | #: E712
|
||||
|
@ -40,7 +40,7 @@ E712.py:5:4: E712 [*] Avoid inequality comparisons to `False`; use `if res:` for
|
|||
7 7 | #: E712
|
||||
8 8 | if True != res:
|
||||
|
||||
E712.py:8:4: E712 [*] Avoid inequality comparisons to `True`; use `if not res:` for false checks
|
||||
E712.py:8:4: E712 [*] Avoid inequality comparisons to `True`; use `not res:` for false checks
|
||||
|
|
||||
6 | pass
|
||||
7 | #: E712
|
||||
|
@ -61,7 +61,7 @@ E712.py:8:4: E712 [*] Avoid inequality comparisons to `True`; use `if not res:`
|
|||
10 10 | #: E712
|
||||
11 11 | if False == res:
|
||||
|
||||
E712.py:11:4: E712 [*] Avoid equality comparisons to `False`; use `if not res:` for false checks
|
||||
E712.py:11:4: E712 [*] Avoid equality comparisons to `False`; use `not res:` for false checks
|
||||
|
|
||||
9 | pass
|
||||
10 | #: E712
|
||||
|
@ -82,7 +82,7 @@ E712.py:11:4: E712 [*] Avoid equality comparisons to `False`; use `if not res:`
|
|||
13 13 | #: E712
|
||||
14 14 | if res[1] == True:
|
||||
|
||||
E712.py:14:4: E712 [*] Avoid equality comparisons to `True`; use `if res[1]:` for truth checks
|
||||
E712.py:14:4: E712 [*] Avoid equality comparisons to `True`; use `res[1]:` for truth checks
|
||||
|
|
||||
12 | pass
|
||||
13 | #: E712
|
||||
|
@ -103,7 +103,7 @@ E712.py:14:4: E712 [*] Avoid equality comparisons to `True`; use `if res[1]:` fo
|
|||
16 16 | #: E712
|
||||
17 17 | if res[1] != False:
|
||||
|
||||
E712.py:17:4: E712 [*] Avoid inequality comparisons to `False`; use `if res[1]:` for truth checks
|
||||
E712.py:17:4: E712 [*] Avoid inequality comparisons to `False`; use `res[1]:` for truth checks
|
||||
|
|
||||
15 | pass
|
||||
16 | #: E712
|
||||
|
@ -124,7 +124,7 @@ E712.py:17:4: E712 [*] Avoid inequality comparisons to `False`; use `if res[1]:`
|
|||
19 19 | #: E712
|
||||
20 20 | var = 1 if cond == True else -1 if cond == False else cond
|
||||
|
||||
E712.py:20:12: E712 [*] Avoid equality comparisons to `True`; use `if cond:` for truth checks
|
||||
E712.py:20:12: E712 [*] Avoid equality comparisons to `True`; use `cond:` for truth checks
|
||||
|
|
||||
18 | pass
|
||||
19 | #: E712
|
||||
|
@ -145,7 +145,7 @@ E712.py:20:12: E712 [*] Avoid equality comparisons to `True`; use `if cond:` for
|
|||
22 22 | if (True) == TrueElement or x == TrueElement:
|
||||
23 23 | pass
|
||||
|
||||
E712.py:20:36: E712 [*] Avoid equality comparisons to `False`; use `if not cond:` for false checks
|
||||
E712.py:20:36: E712 [*] Avoid equality comparisons to `False`; use `not cond:` for false checks
|
||||
|
|
||||
18 | pass
|
||||
19 | #: E712
|
||||
|
@ -166,7 +166,7 @@ E712.py:20:36: E712 [*] Avoid equality comparisons to `False`; use `if not cond:
|
|||
22 22 | if (True) == TrueElement or x == TrueElement:
|
||||
23 23 | pass
|
||||
|
||||
E712.py:22:4: E712 [*] Avoid equality comparisons to `True`; use `if TrueElement:` for truth checks
|
||||
E712.py:22:4: E712 [*] Avoid equality comparisons to `True`; use `TrueElement:` for truth checks
|
||||
|
|
||||
20 | var = 1 if cond == True else -1 if cond == False else cond
|
||||
21 | #: E712
|
||||
|
@ -226,7 +226,7 @@ E712.py:25:4: E712 [*] Avoid equality comparisons to `True` or `False`
|
|||
27 27 |
|
||||
28 28 | if(True) == TrueElement or x == TrueElement:
|
||||
|
||||
E712.py:28:3: E712 [*] Avoid equality comparisons to `True`; use `if TrueElement:` for truth checks
|
||||
E712.py:28:3: E712 [*] Avoid equality comparisons to `True`; use `TrueElement:` for truth checks
|
||||
|
|
||||
26 | pass
|
||||
27 |
|
||||
|
@ -246,7 +246,7 @@ E712.py:28:3: E712 [*] Avoid equality comparisons to `True`; use `if TrueElement
|
|||
30 30 |
|
||||
31 31 | if (yield i) == True:
|
||||
|
||||
E712.py:31:4: E712 [*] Avoid equality comparisons to `True`; use `if yield i:` for truth checks
|
||||
E712.py:31:4: E712 [*] Avoid equality comparisons to `True`; use `yield i:` for truth checks
|
||||
|
|
||||
29 | pass
|
||||
30 |
|
||||
|
@ -266,7 +266,7 @@ E712.py:31:4: E712 [*] Avoid equality comparisons to `True`; use `if yield i:` f
|
|||
33 33 |
|
||||
34 34 | #: Okay
|
||||
|
||||
E712.py:58:4: E712 [*] Avoid equality comparisons to `True`; use `if True:` for truth checks
|
||||
E712.py:58:4: E712 [*] Avoid equality comparisons to `True`; use `True:` for truth checks
|
||||
|
|
||||
57 | # https://github.com/astral-sh/ruff/issues/17582
|
||||
58 | if True == True: # No duplicated diagnostic
|
||||
|
|
|
@ -106,7 +106,7 @@ constant_literals.py:12:4: F632 [*] Use `==` to compare constant literals
|
|||
14 14 | if False == None: # E711, E712 (fix)
|
||||
15 15 | pass
|
||||
|
||||
constant_literals.py:14:4: E712 [*] Avoid equality comparisons to `False`; use `if not None:` for false checks
|
||||
constant_literals.py:14:4: E712 [*] Avoid equality comparisons to `False`; use `not None:` for false checks
|
||||
|
|
||||
12 | if False is "abc": # F632 (fix, but leaves behind unfixable E712)
|
||||
13 | pass
|
||||
|
@ -168,7 +168,7 @@ constant_literals.py:16:4: E711 [*] Comparison to `None` should be `cond is None
|
|||
18 18 |
|
||||
19 19 | named_var = []
|
||||
|
||||
constant_literals.py:16:4: E712 [*] Avoid equality comparisons to `False`; use `if not None:` for false checks
|
||||
constant_literals.py:16:4: E712 [*] Avoid equality comparisons to `False`; use `not None:` for false checks
|
||||
|
|
||||
14 | if False == None: # E711, E712 (fix)
|
||||
15 | pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue