Debian Codegraph @

test/static_analysis/try_except.py

raw symbols SCIP
1 try:
2 #! 4 attribute-error
3 str.not_existing
4 except TypeError:
5 pass
6
7 try:
8 str.not_existing
9 except AttributeError:
10 #! 4 attribute-error
11 str.not_existing
12 pass
13
14 try:
15 import not_existing_import
16 except ImportError:
17 pass
18 try:
19 #! 7 import-error
20 import not_existing_import2
21 except AttributeError:
22 pass
23
24 # -----------------
25 # multi except
26 # -----------------
27 try:
28 str.not_existing
29 except (TypeError, AttributeError): pass
30
31 try:
32 str.not_existing
33 except ImportError:
34 pass
35 except (NotImplementedError, AttributeError): pass
36
37 try:
38 #! 4 attribute-error
39 str.not_existing
40 except (TypeError, NotImplementedError): pass
41
42 # -----------------
43 # detailed except
44 # -----------------
45 try:
46 str.not_existing
47 except ((AttributeError)): pass
48 try:
49 #! 4 attribute-error
50 str.not_existing
51 except [AttributeError]: pass
52
53 # Should be able to detect errors in except statement as well.
54 try:
55 pass
56 #! 7 name-error
57 except Undefined:
58 pass
59
60 # -----------------
61 # inheritance
62 # -----------------
63
64 try:
65 undefined
66 except Exception:
67 pass
68
69 # should catch everything
70 try:
71 undefined
72 except:
73 pass
74
75 # -----------------
76 # kind of similar: hasattr
77 # -----------------
78
79 if hasattr(str, 'undefined'):
80 str.undefined
81 str.upper
82 #! 4 attribute-error
83 str.undefined2
84 #! 4 attribute-error
85 int.undefined
86 else:
87 str.upper
88 #! 4 attribute-error
89 str.undefined
90
91 # -----------------
92 # arguments
93 # -----------------
94
95 def i_see(r):
96 return r
97
98 def lala():
99 # This weird structure checks if the error is actually resolved in the
100 # right place.
101 a = TypeError
102 try:
103 i_see()
104 except a:
105 pass
106 #! 5 type-error-too-few-arguments
107 i_see()