summaryrefslogtreecommitdiff
path: root/tests/functional/r/raise/raise_missing_from.py
blob: d23cefb5e1a7a94a842115ad4ec02364d3ae4807 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# pylint:disable=missing-docstring, unreachable, using-constant-test, invalid-name, bare-except
# pylint:disable=try-except-raise, undefined-variable, too-few-public-methods, superfluous-parens

################################################################################
# Positives:

try:
    1 / 0
except ZeroDivisionError:
    # +1: [raise-missing-from]
    raise KeyError

try:
    1 / 0
except ZeroDivisionError:
    # Our algorithm doesn't have to be careful about the complicated expression below, because
    # the exception above wasn't bound to a name.
    # +1: [raise-missing-from]
    raise (foo + bar).baz

try:
    1 / 0
except ZeroDivisionError as e:
    # +1: [raise-missing-from]
    raise KeyError

try:
    1 / 0
except ZeroDivisionError as e:
    # +1: [raise-missing-from]
    raise KeyError
else:
    pass
finally:
    pass

try:
    1 / 0
except ZeroDivisionError as e:
    if 1:
        if 1:
            with whatever:
                try:
                    # +1: [raise-missing-from]
                    raise KeyError
                except:
                    pass

try:
    1 / 0
except ZeroDivisionError as e:
    # +1: [raise-missing-from]
    raise KeyError()

try:
    1 / 0
except ZeroDivisionError as e:
    # +1: [raise-missing-from]
    raise KeyError(whatever, whatever=whatever)


################################################################################
# Negatives (Same cases as above, except with `from`):

try:
    1 / 0
except ZeroDivisionError:
    raise KeyError from foo

try:
    1 / 0
except ZeroDivisionError:
    raise (foo + bar).baz from foo

try:
    1 / 0
except ZeroDivisionError as e:
    raise KeyError from foo

try:
    1 / 0
except ZeroDivisionError as e:
    raise KeyError from foo
else:
    pass
finally:
    pass

try:
    1 / 0
except ZeroDivisionError as e:
    if 1:
        if 1:
            with whatever:
                try:
                    raise KeyError from foo
                except:
                    pass

try:
    1 / 0
except ZeroDivisionError as e:
    raise KeyError() from foo

try:
    1 / 0
except ZeroDivisionError as e:
    raise KeyError(whatever, whatever=whatever) from foo


################################################################################
# Other negatives:

try:
    1 / 0
except ZeroDivisionError:
    raise

try:
    1 / 0
except ZeroDivisionError as e:
    raise

try:
    1 / 0
except ZeroDivisionError as e:
    raise e

try:
    1 / 0
except ZeroDivisionError as e:
    if 1:
        if 1:
            if 1:
                raise e

try:
    1 / 0
except ZeroDivisionError as e:
    raise e.with_traceback(e.__traceback__)

try:
    1 / 0
except ZeroDivisionError as e:
    raise (e + 7)

try:
    1 / 0
except ZeroDivisionError as e:
    def f():
        raise KeyError

try:
    1 / 0
except ZeroDivisionError as e:
    class Foo:
        raise KeyError