-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[pycodestyle
] Auto-fix redundant boolean comparison (E712
)
#17090
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
Changes from 7 commits
8a6c711
7c7a250
649eff8
5c30c97
03d6275
1118724
63258a6
f45c98b
2cd6971
246c858
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ E712.py:2:4: E712 [*] Avoid equality comparisons to `True`; use `if res:` for tr | |
ℹ Unsafe fix | ||
1 1 | #: E712 | ||
2 |-if res == True: | ||
2 |+if res is True: | ||
2 |+if res: | ||
3 3 | pass | ||
4 4 | #: E712 | ||
5 5 | if res != False: | ||
|
@@ -35,7 +35,7 @@ E712.py:5:4: E712 [*] Avoid inequality comparisons to `False`; use `if res:` for | |
3 3 | pass | ||
4 4 | #: E712 | ||
5 |-if res != False: | ||
5 |+if res is not False: | ||
5 |+if res: | ||
6 6 | pass | ||
7 7 | #: E712 | ||
8 8 | if True != res: | ||
|
@@ -56,7 +56,7 @@ E712.py:8:4: E712 [*] Avoid inequality comparisons to `True`; use `if not res:` | |
6 6 | pass | ||
7 7 | #: E712 | ||
8 |-if True != res: | ||
8 |+if True is not res: | ||
8 |+if not res: | ||
9 9 | pass | ||
10 10 | #: E712 | ||
11 11 | if False == res: | ||
|
@@ -77,7 +77,7 @@ E712.py:11:4: E712 [*] Avoid equality comparisons to `False`; use `if not res:` | |
9 9 | pass | ||
10 10 | #: E712 | ||
11 |-if False == res: | ||
11 |+if False is res: | ||
11 |+if not res: | ||
12 12 | pass | ||
13 13 | #: E712 | ||
14 14 | if res[1] == True: | ||
|
@@ -98,7 +98,7 @@ E712.py:14:4: E712 [*] Avoid equality comparisons to `True`; use `if res[1]:` fo | |
12 12 | pass | ||
13 13 | #: E712 | ||
14 |-if res[1] == True: | ||
14 |+if res[1] is True: | ||
14 |+if res[1]: | ||
15 15 | pass | ||
16 16 | #: E712 | ||
17 17 | if res[1] != False: | ||
|
@@ -119,7 +119,7 @@ E712.py:17:4: E712 [*] Avoid inequality comparisons to `False`; use `if res[1]:` | |
15 15 | pass | ||
16 16 | #: E712 | ||
17 |-if res[1] != False: | ||
17 |+if res[1] is not False: | ||
17 |+if res[1]: | ||
18 18 | pass | ||
19 19 | #: E712 | ||
20 20 | var = 1 if cond == True else -1 if cond == False else cond | ||
|
@@ -140,7 +140,7 @@ E712.py:20:12: E712 [*] Avoid equality comparisons to `True`; use `if cond:` for | |
18 18 | pass | ||
19 19 | #: E712 | ||
20 |-var = 1 if cond == True else -1 if cond == False else cond | ||
20 |+var = 1 if cond is True else -1 if cond == False else cond | ||
20 |+var = 1 if cond else -1 if cond == False else cond | ||
21 21 | #: E712 | ||
22 22 | if (True) == TrueElement or x == TrueElement: | ||
23 23 | pass | ||
|
@@ -161,7 +161,7 @@ E712.py:20:36: E712 [*] Avoid equality comparisons to `False`; use `if not cond: | |
18 18 | pass | ||
19 19 | #: E712 | ||
20 |-var = 1 if cond == True else -1 if cond == False else cond | ||
20 |+var = 1 if cond == True else -1 if cond is False else cond | ||
20 |+var = 1 if cond == True else -1 if not cond else cond | ||
21 21 | #: E712 | ||
22 22 | if (True) == TrueElement or x == TrueElement: | ||
23 23 | pass | ||
|
@@ -181,7 +181,7 @@ E712.py:22:4: E712 [*] Avoid equality comparisons to `True`; use `if TrueElement | |
20 20 | var = 1 if cond == True else -1 if cond == False else cond | ||
21 21 | #: E712 | ||
22 |-if (True) == TrueElement or x == TrueElement: | ||
22 |+if (True) is TrueElement or x == TrueElement: | ||
22 |+if (TrueElement) or x == TrueElement: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, is the parenthesis detection wrong here? I don't think we need these parens. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the logic, the comparison of the start indexes is on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the point I was trying to make is that I would rather not have these parentheses because the expression is valid without them. I would have expected this output here: if TrueElement or x == TrueElement:
... The current logic may not be correct if it preserves unnecessary parentheses. I tried a couple of approaches to get rid of the |
||
23 23 | pass | ||
24 24 | | ||
25 25 | if res == True != False: | ||
|
@@ -241,7 +241,7 @@ E712.py:28:3: E712 [*] Avoid equality comparisons to `True`; use `if TrueElement | |
26 26 | pass | ||
27 27 | | ||
28 |-if(True) == TrueElement or x == TrueElement: | ||
28 |+if(True) is TrueElement or x == TrueElement: | ||
28 |+if(TrueElement) or x == TrueElement: | ||
29 29 | pass | ||
30 30 | | ||
31 31 | if (yield i) == True: | ||
|
@@ -261,7 +261,7 @@ E712.py:31:4: E712 [*] Avoid equality comparisons to `True`; use `if yield i:` f | |
29 29 | pass | ||
30 30 | | ||
31 |-if (yield i) == True: | ||
31 |+if (yield i) is True: | ||
31 |+if (yield i): | ||
32 32 | print("even") | ||
33 33 | | ||
34 34 | #: Okay |
Uh oh!
There was an error while loading. Please reload this page.