blob: 835eb73cf237ea82d6a1486762b94108eb944b88 (
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
|
"""Test for old tenrary constructs"""
from UNINFERABLE import condition, true_value, false_value, some_callable # pylint: disable=import-error
SOME_VALUE1 = true_value if condition else false_value
SOME_VALUE2 = condition and true_value or false_value # [consider-using-ternary]
SOME_VALUE3 = condition
def func1():
"""Ternary return value correct"""
return true_value if condition else false_value
def func2():
"""Ternary return value incorrect"""
return condition and true_value or false_value # [consider-using-ternary]
SOME_VALUE4 = some_callable(condition) and 'ERROR' or 'SUCCESS' # [consider-using-ternary]
SOME_VALUE5 = SOME_VALUE1 > 3 and 'greater' or 'not greater' # [consider-using-ternary]
SOME_VALUE6 = (SOME_VALUE2 > 4 and SOME_VALUE3) and 'both' or 'not' # [consider-using-ternary]
SOME_VALUE7 = 'both' if (SOME_VALUE2 > 4) and (SOME_VALUE3) else 'not'
SOME_VALUE8 = SOME_VALUE1 and SOME_VALUE2 and SOME_VALUE3 or SOME_VALUE4
SOME_VALUE9 = SOME_VALUE1 and False or SOME_VALUE2 # [simplify-boolean-expression]
YEAR = 1992
# Cannot be simplified with a ternary.
IS_LEAP_YEAR = YEAR % 4 == 0 and YEAR % 100 != 0 or YEAR % 400 == 0
def func4():
""""Using a Name as a condition but still emits"""
truth_value = 42
return condition and truth_value or false_value # [consider-using-ternary]
|