summaryrefslogtreecommitdiff
path: root/tests/functional/no_else_raise.py
blob: b3f27a74e03940382fcf98f5ce8ad7b9ecabf49f (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
102
103
104
105
106
107
108
109
110
""" Test that superfluous else return are detected. """

# pylint:disable=invalid-name,missing-docstring,unused-variable

def foo1(x, y, z):
    if x:  # [no-else-raise]
        a = 1
        raise Exception(y)
    else:
        b = 2
        raise Exception(z)


def foo2(x, y, w, z):
    if x:  # [no-else-raise]
        a = 1
        raise Exception(y)
    elif z:
        b = 2
        raise Exception(w)
    else:
        c = 3
        raise Exception(z)


def foo3(x, y, z):
    if x:
        a = 1
        if y:  # [no-else-raise]
            b = 2
            raise Exception(y)
        else:
            c = 3
            raise Exception(x)
    else:
        d = 4
        raise Exception(z)


def foo4(x, y):
    if x: # [no-else-raise]
        if y:
            a = 4
        else:
            b = 2
        raise Exception(x)
    else:
        c = 3
    raise Exception(y)


def foo5(x, y, z):
    if x: # [no-else-raise]
        if y:
            a = 4
        else:
            b = 2
        raise Exception(x)
    elif z:
        raise Exception(y)
    else:
        c = 3
    raise Exception(z)


def foo6(x, y):
    if x:
        if y:   # [no-else-raise]
            a = 4
            raise Exception(x)
        else:
            b = 2
    else:
        c = 3
    raise Exception(y)


def bar1(x, y, z):
    if x:
        raise Exception(y)
    raise Exception(z)


def bar2(w, x, y, z):
    if x:
        raise Exception(y)
    if z:
        a = 1
    else:
        raise Exception(w)
    raise Exception(None)


def bar3(x, y, z):
    if x:
        if z:
            raise Exception(y)
    else:
        raise Exception(z)
    raise Exception(None)


def bar4(x):
    if x:  # [no-else-raise]
        raise Exception(True)
    else:
        try:
            raise Exception(False)
        except ValueError:
            raise Exception(None)