summaryrefslogtreecommitdiff
path: root/tests/functional/s/simplifiable/simplifiable_condition.py
blob: 32bf36acab81a0a8926bfd340fc031a4e67ed14b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Test that boolean conditions can be simplified"""
# pylint: disable=pointless-statement


def func(_):
    """Pointless function"""


CONSTANT = 100
OTHER = 200

# Simplifies any boolean expression that is coerced into a True/False value
bool(CONSTANT or False)  # [simplifiable-condition]
assert CONSTANT or False  # [simplifiable-condition]
if CONSTANT and True:  # [simplifiable-condition]
    pass
elif CONSTANT and True:  # [simplifiable-condition]
    pass
while CONSTANT and True:  # [simplifiable-condition]
    break
1 if CONSTANT or False else 2  # [simplifiable-condition]
z = [x for x in range(10) if x or False]  # [simplifiable-condition]

# Simplifies recursively
assert CONSTANT or (True and False)  # [simplifiable-condition]
assert True and CONSTANT and OTHER  # [simplifiable-condition]
assert (CONSTANT or False) and (OTHER or True)  # [simplifiable-condition]

# Will try to infer the truthiness of an expression as long as it doesn't contain any variables
assert [] or CONSTANT  # [simplifiable-condition]
assert {} or CONSTANT  # [simplifiable-condition]

# Expressions not in one of the above situations will not emit a message
CONSTANT or True
bool(CONSTANT or OTHER)
bool(func(CONSTANT or True))