diff -r de4ae767b0e3 -r 251638443e17 src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Unused/UnusedChecker.py --- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Unused/UnusedChecker.py Wed May 24 19:54:24 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Unused/UnusedChecker.py Thu May 25 11:06:31 2023 +0200 @@ -171,6 +171,14 @@ ): continue + # TODO: add 'IgnoreEventHandlerMethods' to ignore Qt event handlers + # - function name ends with 'Event' + # - function name is 'event' or 'eventFilter' + if self.__args["IgnoreEventHandlerMethods"] and self.__isEventHandlerMethod( + functionNode + ): + continue + # ignore stub functions if self.__args["IgnoreStubs"] and self.__isStubFunction(functionNode): continue @@ -294,6 +302,28 @@ name = functionNode.name return len(name) > 4 and name.startswith("__") and name.endswith("__") + def __isEventHandlerMethod(self, functionNode): + """ + Private method to check, if the function node defines a Qt event handler. + + Qt event handler methods are assumed to end with 'Event' or have the name + 'event' or 'eventFilter'. Only standard methodes (i.e. ast.FunctionDef) + are assumed to be potential event handlers. + + @param functionNode reference to the node defining the function or lambda + @type ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda + @return flag indicating a Qt event handler method + @rtype bool + """ + if isinstance(functionNode, (ast.Lambda, ast.AsyncFunctionDef)): + return False + + if not hasattr(functionNode, "name"): + return False + + name = functionNode.name + return name.endswith("Event") or name in ("event", "eventFilter") + def __getUnusedArguments(self, functionNode): """ Private method to get a list of unused arguments of the given function.