File tree Expand file tree Collapse file tree
tests/test_visitors/test_ast/test_operators Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ Semantic versioning in our case means:
1717 change the client facing API, change code conventions significantly, etc.
1818
1919
20+ ## WIP
21+
22+ ### Bugfixes
23+
24+ - Fixes false positive ` WPS366 ` allowing the use of a single constant in ` or ` , #3610
25+
2026## 1.6.0
2127
2228### Features
Original file line number Diff line number Diff line change 1818 # `and` containing at least one constant
1919 'value and True' ,
2020 'value1 and 4 and value2 and "py" and True' ,
21- # `or` containing True/False
22- 'value or False' ,
21+ # `or` containing everythhing after constant
22+ 'value or False or True ' ,
2323 'value1 or True or value2 or False or False' ,
24- # `or` containing everything after non-bool constant
2524 'value1 or 0 or value2' ,
2625 'value or "py" or 4' ,
2726 # `and`/`or` operators containing a duplicate name
@@ -54,6 +53,9 @@ def test_useless_bool(
5453@pytest .mark .parametrize (
5554 'expression' ,
5655 [
56+ 'value or True' ,
57+ 'value or False' ,
58+ 'value or 0' ,
5759 'value or -value or ~value' ,
5860 'value1 or value2 or value3' ,
5961 'value1 or value2 or 4' ,
Original file line number Diff line number Diff line change @@ -2482,14 +2482,9 @@ class MeaninglessBooleanOperationViolation(ASTViolation):
24822482
24832483 Explanation:
24842484 - comparison of constants can be replaced with a single constant
2485- - comparison with ``True``/``False`` can be removed or replaced
2486- with ``True`` or ``False`` constant
24872485 - comparison with constants in the ``and`` operator can lead to
24882486 an implicit conditional assignment, which is better done explicitly
2489- - comparison with false-like constants in the ``or`` operator
2490- can be removed
2491- - everything after the first true-like constant in ``or`` operator
2492- can be removed
2487+ - everything after the first constant in ``or`` operator can be removed
24932488 - comparison of duplicated variables can be reduced
24942489
24952490 Solution:
@@ -2506,7 +2501,7 @@ class MeaninglessBooleanOperationViolation(ASTViolation):
25062501 # Wrong:
25072502 cond = 10 and 'value'
25082503 cond = condition and 10
2509- cond = condition or True
2504+ cond = condition or True or 2
25102505 cond = condition or 'value' or 0
25112506 cond = condition and condition
25122507
Original file line number Diff line number Diff line change @@ -133,11 +133,9 @@ def _check_useless_bool_op_constants(
133133 unwrapped = unwrap_unary_node (node )
134134
135135 # `and` containing at least one constant
136- # `or` containing bool or everything after non-bool constant
136+ # `or` containing everythhing after constant
137137 has_useless_constant = isinstance (unwrapped , ast .Constant ) and (
138- isinstance (op , ast .And )
139- or isinstance (unwrapped .value , bool )
140- or position < len (nodes )
138+ isinstance (op , ast .And ) or position < len (nodes )
141139 )
142140 if has_useless_constant :
143141 self .add_violation (
You can’t perform that action at this time.
0 commit comments