1
def single_except(a, x):
3
>>> single_except(ValueError, None)
5
>>> single_except(ValueError, ValueError('test'))
7
>>> single_except(ValueError, TypeError('test'))
8
Traceback (most recent call last):
21
def single_except_builtin(a, x):
23
>>> single_except_builtin(ValueError, None)
25
>>> single_except_builtin(ValueError, ValueError('test'))
27
>>> single_except_builtin(ValueError, TypeError('test'))
28
Traceback (most recent call last):
41
def single_except_expression(a, x):
43
>>> single_except_expression([[ValueError]], None)
45
>>> single_except_expression([[ValueError]], ValueError('test'))
47
>>> single_except_expression([[ValueError]], TypeError('test'))
48
Traceback (most recent call last):
62
exceptions = (ValueError, TypeError)
65
def single_except_global_tuple(x):
67
>>> single_except_global_tuple(None)
69
>>> single_except_global_tuple(ValueError('test'))
71
>>> single_except_global_tuple(TypeError('test'))
73
>>> class TypeErrorSubtype(TypeError): pass
74
>>> single_except_global_tuple(TypeErrorSubtype('test'))
76
>>> single_except_global_tuple(AttributeError('test'))
77
Traceback (most recent call last):
91
def double_except_no_raise(a,b):
93
>>> double_except_no_raise(TypeError, ValueError)
96
d = a or b # mark used
107
def double_except_raise(x, a, b):
109
>>> double_except_raise(None, TypeError, ValueError)
111
>>> double_except_raise(TypeError('test'), TypeError, ValueError)
113
>>> double_except_raise(ValueError('test'), TypeError, ValueError)
115
>>> double_except_raise(None, TypeError, ValueError)
129
def target_except_no_raise(a):
131
>>> target_except_no_raise(TypeError)
143
def target_except_raise(x, a):
145
>>> target_except_raise(None, TypeError)
147
>>> target_except_raise(TypeError('test'), TypeError)
149
>>> target_except_raise(ValueError('test'), TypeError)
150
Traceback (most recent call last):
152
>>> target_except_raise(None, TypeError)
162
assert isinstance(b, a)
165
def tuple_except_builtin(x):
167
>>> tuple_except_builtin(None)
169
>>> tuple_except_builtin(TypeError('test'))
171
>>> tuple_except_builtin(ValueError('test'))
173
>>> tuple_except_builtin(IndexError('5'))
174
Traceback (most recent call last):
176
>>> tuple_except_builtin(None)
184
except (TypeError, ValueError):
188
def normal_and_bare_except_no_raise(a):
190
>>> normal_and_bare_except_no_raise(TypeError)
204
def normal_and_bare_except_raise(x, a):
206
>>> normal_and_bare_except_raise(None, TypeError)
208
>>> normal_and_bare_except_raise(TypeError('test'), TypeError)
210
>>> normal_and_bare_except_raise(ValueError('test'), TypeError)
212
>>> normal_and_bare_except_raise(TypeError('test'), (TypeError, ValueError))
214
>>> normal_and_bare_except_raise(ValueError('test'), (TypeError, ValueError))
216
>>> normal_and_bare_except_raise(None, TypeError)
230
def tuple_except_index_target_no_raise(a, b, c):
233
>>> tuple_except_index_target_no_raise(TypeError, ValueError, l)
238
d = a or b or c # mark used
247
def tuple_except_index_target_raise(x, a, b, c):
250
>>> tuple_except_index_target_raise(None, TypeError, ValueError, l)
254
>>> tuple_except_index_target_raise(TypeError('test'), TypeError, ValueError, l)
256
>>> l[0] is None, isinstance(l[1], TypeError)
258
>>> tuple_except_index_target_raise(ValueError('test'), TypeError, ValueError, l)
260
>>> l[0] is None, isinstance(l[1], ValueError)
262
>>> tuple_except_index_target_raise(IndexError('5'), TypeError, ValueError, l)
263
Traceback (most recent call last):
265
>>> tuple_except_index_target_raise(None, TypeError, ValueError, l)
267
>>> l[0] is None, isinstance(l[1], ValueError)
277
assert isinstance(c[1], (a,b))
280
def loop_bare_except_no_raise(a, b, int c):
282
>>> loop_bare_except_no_raise(TypeError, range(2), 2)
293
def loop_bare_except_raise(a, b, int c):
295
>>> loop_bare_except_raise(TypeError, range(2), 2)
297
>>> loop_bare_except_raise(TypeError, range(3), 2)
299
>>> loop_bare_except_raise(TypeError, range(4), 2)
307
raise TypeError('test')
312
def bare_except_reraise_no_raise(l):
315
>>> bare_except_reraise_no_raise(l)
330
def bare_except_reraise_raise(x, l):
333
>>> bare_except_reraise_raise(None, l)
337
>>> bare_except_reraise_raise(TypeError('test'), l)
338
Traceback (most recent call last):
343
>>> bare_except_reraise_raise(None, l)
358
def except_as_no_raise(a):
360
>>> except_as_no_raise(TypeError)
371
def except_as_raise(x, a):
373
>>> except_as_raise(None, TypeError)
375
>>> except_as_raise(TypeError('test'), TypeError)
377
>>> except_as_raise(ValueError('test'), TypeError)
378
Traceback (most recent call last):
380
>>> except_as_raise(None, TypeError)
389
assert isinstance(b, a)
392
def except_as_no_raise_does_not_touch_target(a):
394
>>> i,b = except_as_no_raise_does_not_touch_target(TypeError)
409
def except_as_raise_does_not_delete_target(x, a):
411
>>> except_as_raise_does_not_delete_target(None, TypeError)
413
>>> except_as_raise_does_not_delete_target(TypeError('test'), TypeError)
415
>>> except_as_raise_does_not_delete_target(ValueError('test'), TypeError)
416
Traceback (most recent call last):
418
>>> except_as_raise_does_not_delete_target(None, TypeError)
428
assert isinstance(b, a)
430
# exception variable leaks with Py2 except-as semantics
432
assert isinstance(b, a)
437
def except_as_raise_with_empty_except(x, a):
439
>>> except_as_raise_with_empty_except(None, TypeError)
440
>>> except_as_raise_with_empty_except(TypeError('test'), TypeError)
441
>>> except_as_raise_with_empty_except(ValueError('test'), TypeError)
442
Traceback (most recent call last):
444
>>> except_as_raise_with_empty_except(None, TypeError)
453
assert isinstance(b, a)
457
def complete_except_as_no_raise(a, b):
459
>>> complete_except_as_no_raise(TypeError, ValueError)
462
d = a or b # mark used
476
def complete_except_as_raise(x, a, b):
478
>>> complete_except_as_raise(None, TypeError, ValueError)
480
>>> complete_except_as_raise(TypeError('test'), TypeError, ValueError)
482
>>> complete_except_as_raise(ValueError('test'), TypeError, ValueError)
484
>>> complete_except_as_raise(IndexError('5'), TypeError, ValueError)
486
>>> complete_except_as_raise(None, TypeError, ValueError)
495
assert isinstance(c, (a, b))
498
assert isinstance(c, (a, b))
506
def try_except_raise_new(initial, catch, throw):
508
>>> try_except_raise_new(None, TypeError, ValueError)
509
>>> try_except_raise_new(TypeError, IndexError, ValueError)
510
Traceback (most recent call last):
512
>>> try_except_raise_new(TypeError, TypeError, ValueError)
513
Traceback (most recent call last):
517
if initial is not None: