src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/tryExcept.py

branch
eric7
changeset 9325
8157eb19aba5
parent 9221
bf71ee032bb4
child 9327
2b768afcaee1
equal deleted inserted replaced
9324:7f7f3e47b238 9325:8157eb19aba5
30 """ 30 """
31 return { 31 return {
32 "ExceptHandler": [ 32 "ExceptHandler": [
33 (checkTryExceptPass, ("S110",)), 33 (checkTryExceptPass, ("S110",)),
34 (checkTryExceptContinue, ("S112",)), 34 (checkTryExceptContinue, ("S112",)),
35 ],
36 "Call": [
37 (checkContextlibSuppress, ("S113",)),
35 ], 38 ],
36 } 39 }
37 40
38 41
39 def checkTryExceptPass(reportError, context, config): 42 def checkTryExceptPass(reportError, context, config):
104 context.node.col_offset, 107 context.node.col_offset,
105 "S112", 108 "S112",
106 "L", 109 "L",
107 "H", 110 "H",
108 ) 111 )
112
113
114 def checkContextlibSuppress(reportError, context, config):
115 """
116 Function to check for a contextlib.suppress with a non-specific Exception.
117
118 @param reportError function to be used to report errors
119 @type func
120 @param context security context object
121 @type SecurityContext
122 @param config dictionary with configuration data
123 @type dict
124 """
125 checkTypedException = (
126 config["check_typed_exception"]
127 if config and "check_typed_exception" in config
128 else SecurityDefaults["check_typed_exception"]
129 )
130
131 imported = context.isModuleImportedExact("contextlib")
132 qualname = context.callFunctionNameQual
133 if not imported and isinstance(qualname, str):
134 return
135
136 qualnameList = qualname.split(".")
137 func = qualnameList[-1]
138 if func == "suppress":
139 if not checkTypedException and "Exception" not in context.callArgs:
140 return
141
142 reportError(
143 context.node.lineno - 1,
144 context.node.col_offset,
145 "S113",
146 "L",
147 "H",
148 )

eric ide

mercurial