Debian Codegraph @

tests/data/cases/remove_except_parens.py

raw
1 # These brackets are redundant, therefore remove.
2 try:
3 a.something
4 except (AttributeError) as err:
5 raise err
6
7 # This is tuple of exceptions.
8 # Although this could be replaced with just the exception,
9 # we do not remove brackets to preserve AST.
10 try:
11 a.something
12 except (AttributeError,) as err:
13 raise err
14
15 # This is a tuple of exceptions. Do not remove brackets.
16 try:
17 a.something
18 except (AttributeError, ValueError) as err:
19 raise err
20
21 # Test long variants.
22 try:
23 a.something
24 except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
25 raise err
26
27 try:
28 a.something
29 except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err:
30 raise err
31
32 try:
33 a.something
34 except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
35 raise err
36
37 # output
38 # These brackets are redundant, therefore remove.
39 try:
40 a.something
41 except AttributeError as err:
42 raise err
43
44 # This is tuple of exceptions.
45 # Although this could be replaced with just the exception,
46 # we do not remove brackets to preserve AST.
47 try:
48 a.something
49 except (AttributeError,) as err:
50 raise err
51
52 # This is a tuple of exceptions. Do not remove brackets.
53 try:
54 a.something
55 except (AttributeError, ValueError) as err:
56 raise err
57
58 # Test long variants.
59 try:
60 a.something
61 except (
62 some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error
63 ) as err:
64 raise err
65
66 try:
67 a.something
68 except (
69 some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
70 ) as err:
71 raise err
72
73 try:
74 a.something
75 except (
76 some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
77 some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
78 ) as err:
79 raise err