summaryrefslogtreecommitdiff
path: root/tests/functional/len_checks.py
blob: e8e61afadbcccce80a0dafeaa73448c951c08ad0 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# pylint: disable=too-few-public-methods,import-error, no-absolute-import,missing-docstring, misplaced-comparison-constant
# pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order

if len('TEST'):  # [len-as-condition]
    pass

if not len('TEST'):  # [len-as-condition]
    pass

z = False
if z and len(['T', 'E', 'S', 'T']):  # [len-as-condition]
    pass

if True or len('TEST'):  # [len-as-condition]
    pass

if len('TEST') == 0:  # Should be fine
    pass

if len('TEST') < 1:  # Should be fine
    pass

if len('TEST') <= 0:  # Should be fine
    pass

if 1 > len('TEST'):  # Should be fine
    pass

if 0 >= len('TEST'):  # Should be fine
    pass

if z and len('TEST') == 0:  # Should be fine
    pass

if 0 == len('TEST') < 10:  # Should be fine
    pass

if 0 < 1 <= len('TEST') < 10:  # Should be fine
    pass

if 10 > len('TEST') != 0:  # Should be fine
    pass

if 10 > len('TEST') > 1 > 0:  # Should be fine
    pass

if 0 <= len('TEST') < 100:  # Should be fine
    pass

if z or 10 > len('TEST') != 0:  # Should be fine
    pass

if z:
    pass
elif len('TEST'):  # [len-as-condition]
    pass

if z:
    pass
elif not len('TEST'):  # [len-as-condition]
    pass

while len('TEST'):  # [len-as-condition]
    pass

while not len('TEST'):  # [len-as-condition]
    pass

while z and len('TEST'):  # [len-as-condition]
    pass

while not len('TEST') and z:  # [len-as-condition]
    pass

assert len('TEST') > 0  # Should be fine

x = 1 if len('TEST') != 0 else 2  # Should be fine

f_o_o = len('TEST') or 42  # Should be fine

a = x and len(x)  # Should be fine

def some_func():
    return len('TEST') > 0  # Should be fine

def github_issue_1325():
    l = [1, 2, 3]
    length = len(l) if l else 0  # Should be fine
    return length

def github_issue_1331(*args):
    assert False, len(args)  # Should be fine

def github_issue_1331_v2(*args):
    assert len(args), args  # [len-as-condition]

def github_issue_1331_v3(*args):
    assert len(args) or z, args  # [len-as-condition]

def github_issue_1331_v4(*args):
    assert z and len(args), args  # [len-as-condition]