summaryrefslogtreecommitdiff
path: root/pylint/test/functional/too_many_nested_blocks.py
blob: 8d371dda7db833093e9d3b1d081cd5e8ee28295e (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
"""Checks the maximum block level is smaller than 6 in function definitions"""

#pylint: disable=using-constant-test, missing-docstring, too-many-return-statements

def my_function():
    if 1:  # [too-many-nested-blocks]
        for i in range(10):
            if i == 2:
                while True:
                    try:
                        if True:
                            i += 1
                    except IOError:
                        pass

    if 1:
        for i in range(10):
            if i == 2:
                while True:
                    try:
                        i += 1
                    except IOError:
                        pass

    def nested_func():
        if True:
            for i in range(10):
                while True:
                    if True:
                        if True:
                            print i

    nested_func()

def more_complex_function():
    attr1 = attr2 = attr3 = [1, 2, 3]
    if attr1:
        for i in attr1:
            if attr2:
                return i
            else:
                return 'duh'
    elif attr2:
        for i in attr2:
            if attr2:
                return i
            else:
                return 'duh'
    else:
        for i in range(15):
            if attr3:
                return i
            else:
                return 'doh'
            return None

def elif_function():
    arg = None
    if arg == 1:
        return 1
    elif arg == 2:
        return 2
    elif arg == 3:
        return 3
    elif arg == 4:
        return 4
    elif arg == 5:
        return 5
    elif arg == 6:
        return 6
    elif arg == 7:
        return 7

def else_if_function():
    arg = None
    if arg == 1:  # [too-many-nested-blocks]
        return 1
    else:
        if arg == 2:
            return 2
        else:
            if arg == 3:
                return 3
            else:
                if arg == 4:
                    return 4
                else:
                    if arg == 5:
                        return 5
                    else:
                        if arg == 6:
                            return 6
                        else:
                            if arg == 7:
                                return 7