File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
tests/functional/ext/comparetozero Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 2121
2222
2323def _is_constant_zero (node : str | nodes .NodeNG ) -> bool :
24- return isinstance (node , astroid .Const ) and node .value == 0
24+ # We have to check that node.value is not False because node.value == 0 is True
25+ # when node.value is False
26+ return (
27+ isinstance (node , astroid .Const ) and node .value == 0 and node .value is not False
28+ )
2529
2630
2731class CompareToZeroChecker (checkers .BaseChecker ):
Original file line number Diff line number Diff line change 66if X is 0 : # [compare-to-zero]
77 pass
88
9+ if X is False :
10+ pass
11+
912if Y is not 0 : # [compare-to-zero]
1013 pass
1114
15+ if Y is not False :
16+ pass
17+
1218if X == 0 : # [compare-to-zero]
1319 pass
1420
Original file line number Diff line number Diff line change 11compare-to-zero:6:3:6:9::"""X is 0"" can be simplified to ""not X"" as 0 is falsey":HIGH
2- compare-to-zero:9 :3:9 :13::"""Y is not 0"" can be simplified to ""Y"" as 0 is falsey":HIGH
3- compare-to-zero:12 :3:12 :9::"""X == 0"" can be simplified to ""not X"" as 0 is falsey":HIGH
4- compare-to-zero:15 :3:15 :9::"""0 == Y"" can be simplified to ""not Y"" as 0 is falsey":HIGH
5- compare-to-zero:18 :3:18 :9::"""Y != 0"" can be simplified to ""Y"" as 0 is falsey":HIGH
6- compare-to-zero:21 :3:21 :9::"""0 != X"" can be simplified to ""X"" as 0 is falsey":HIGH
2+ compare-to-zero:12 :3:12 :13::"""Y is not 0"" can be simplified to ""Y"" as 0 is falsey":HIGH
3+ compare-to-zero:18 :3:18 :9::"""X == 0"" can be simplified to ""not X"" as 0 is falsey":HIGH
4+ compare-to-zero:21 :3:21 :9::"""0 == Y"" can be simplified to ""not Y"" as 0 is falsey":HIGH
5+ compare-to-zero:24 :3:24 :9::"""Y != 0"" can be simplified to ""Y"" as 0 is falsey":HIGH
6+ compare-to-zero:27 :3:27 :9::"""0 != X"" can be simplified to ""X"" as 0 is falsey":HIGH
You can’t perform that action at this time.
0 commit comments