src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Unused/UnusedChecker.py

branch
eric7
changeset 10066
251638443e17
parent 10056
ac1c214e0a05
child 10127
a7018026aae2
equal deleted inserted replaced
10065:de4ae767b0e3 10066:251638443e17
169 if self.__args["IgnoreSlotMethods"] and ( 169 if self.__args["IgnoreSlotMethods"] and (
170 "pyqtSlot" in decoratorNames or "Slot" in decoratorNames 170 "pyqtSlot" in decoratorNames or "Slot" in decoratorNames
171 ): 171 ):
172 continue 172 continue
173 173
174 # TODO: add 'IgnoreEventHandlerMethods' to ignore Qt event handlers
175 # - function name ends with 'Event'
176 # - function name is 'event' or 'eventFilter'
177 if self.__args["IgnoreEventHandlerMethods"] and self.__isEventHandlerMethod(
178 functionNode
179 ):
180 continue
181
174 # ignore stub functions 182 # ignore stub functions
175 if self.__args["IgnoreStubs"] and self.__isStubFunction(functionNode): 183 if self.__args["IgnoreStubs"] and self.__isStubFunction(functionNode):
176 continue 184 continue
177 185
178 # ignore lambdas 186 # ignore lambdas
292 return False 300 return False
293 301
294 name = functionNode.name 302 name = functionNode.name
295 return len(name) > 4 and name.startswith("__") and name.endswith("__") 303 return len(name) > 4 and name.startswith("__") and name.endswith("__")
296 304
305 def __isEventHandlerMethod(self, functionNode):
306 """
307 Private method to check, if the function node defines a Qt event handler.
308
309 Qt event handler methods are assumed to end with 'Event' or have the name
310 'event' or 'eventFilter'. Only standard methodes (i.e. ast.FunctionDef)
311 are assumed to be potential event handlers.
312
313 @param functionNode reference to the node defining the function or lambda
314 @type ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda
315 @return flag indicating a Qt event handler method
316 @rtype bool
317 """
318 if isinstance(functionNode, (ast.Lambda, ast.AsyncFunctionDef)):
319 return False
320
321 if not hasattr(functionNode, "name"):
322 return False
323
324 name = functionNode.name
325 return name.endswith("Event") or name in ("event", "eventFilter")
326
297 def __getUnusedArguments(self, functionNode): 327 def __getUnusedArguments(self, functionNode):
298 """ 328 """
299 Private method to get a list of unused arguments of the given function. 329 Private method to get a list of unused arguments of the given function.
300 330
301 @param functionNode reference to the node defining the function or lambda 331 @param functionNode reference to the node defining the function or lambda

eric ide

mercurial