--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/tryExcept.py Tue Sep 13 19:46:19 2022 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/tryExcept.py Tue Sep 13 20:00:55 2022 +0200 @@ -33,6 +33,9 @@ (checkTryExceptPass, ("S110",)), (checkTryExceptContinue, ("S112",)), ], + "Call": [ + (checkContextlibSuppress, ("S113",)), + ], } @@ -106,3 +109,40 @@ "L", "H", ) + + +def checkContextlibSuppress(reportError, context, config): + """ + Function to check for a contextlib.suppress with a non-specific Exception. + + @param reportError function to be used to report errors + @type func + @param context security context object + @type SecurityContext + @param config dictionary with configuration data + @type dict + """ + checkTypedException = ( + config["check_typed_exception"] + if config and "check_typed_exception" in config + else SecurityDefaults["check_typed_exception"] + ) + + imported = context.isModuleImportedExact("contextlib") + qualname = context.callFunctionNameQual + if not imported and isinstance(qualname, str): + return + + qualnameList = qualname.split(".") + func = qualnameList[-1] + if func == "suppress": + if not checkTypedException and "Exception" not in context.callArgs: + return + + reportError( + context.node.lineno - 1, + context.node.col_offset, + "S113", + "L", + "H", + )