src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Logging/LoggingVisitor.py

branch
eric7
changeset 11133
d650c9527b87
parent 11132
7cb530e18aba
child 11147
dee6e106b4d3
equal deleted inserted replaced
11132:7cb530e18aba 11133:d650c9527b87
299 if k.arg is not None 299 if k.arg is not None
300 ] 300 ]
301 301
302 for key, keyNode in extraKeys: 302 for key, keyNode in extraKeys:
303 if key in _LogrecordAttributes: 303 if key in _LogrecordAttributes:
304 if isinstance(keyNode, ast.keyword): 304 self.__error(
305 lineno, colOffset = self.__keywordPos(keyNode) 305 keyNode.lineno - 1, keyNode.col_offset, "L103", repr(key)
306 else: 306 )
307 lineno = keyNode.lineno
308 colOffset = keyNode.col_offset
309 self.__error(lineno - 1, colOffset, "L103", repr(key))
310 307
311 if node.func.attr == "exception": 308 if node.func.attr == "exception":
312 # L104 309 # L104
313 if not excHandler: 310 if not excHandler:
314 self.__error(node.lineno - 1, node.col_offset, "L104") 311 self.__error(node.lineno - 1, node.col_offset, "L104")
320 ) or ( 317 ) or (
321 excHandler 318 excHandler
322 and isinstance(excInfo.value, ast.Name) 319 and isinstance(excInfo.value, ast.Name)
323 and excInfo.value.id == excHandler.name 320 and excInfo.value.id == excHandler.name
324 ): 321 ):
325 lineno, colOffset = self.__keywordPos(excInfo) 322 self.__error(excInfo.lineno - 1, excInfo.col_offset, "L106")
326 self.__error(lineno - 1, colOffset, "L106")
327 323
328 # L107 324 # L107
329 elif ( 325 elif (
330 isinstance(excInfo.value, ast.Constant) 326 isinstance(excInfo.value, ast.Constant)
331 and not excInfo.value.value 327 and not excInfo.value.value
332 ): 328 ):
333 lineno, colOffset = self.__keywordPos(excInfo) 329 self.__error(excInfo.lineno - 1, excInfo.col_offset, "L107")
334 self.__error(lineno - 1, colOffset, "L107")
335 330
336 # L105 331 # L105
337 elif node.func.attr == "error" and excHandler is not None: 332 elif node.func.attr == "error" and excHandler is not None:
338 rewritable = False 333 rewritable = False
339 if any((excInfo := kw).arg == "exc_info" for kw in node.keywords): 334 if any((excInfo := kw).arg == "exc_info" for kw in node.keywords):
355 excHandler is None 350 excHandler is None
356 and any((excInfo := kw).arg == "exc_info" for kw in node.keywords) 351 and any((excInfo := kw).arg == "exc_info" for kw in node.keywords)
357 and isinstance(excInfo.value, ast.Constant) 352 and isinstance(excInfo.value, ast.Constant)
358 and excInfo.value.value 353 and excInfo.value.value
359 ): 354 ):
360 lineno, colOffset = self.__keywordPos(excInfo) 355 self.__error(excInfo.lineno - 1, excInfo.col_offset, "L114")
361 self.__error(lineno - 1, colOffset, "L114")
362 356
363 # L110 357 # L110
364 if ( 358 if (
365 node.func.attr == "exception" 359 node.func.attr == "exception"
366 and len(node.args) >= 1 360 and len(node.args) >= 1
508 elif isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef)): 502 elif isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef)):
509 break 503 break
510 504
511 return None 505 return None
512 506
513 def __keywordPos(self, node):
514 """
515 Private method determine line number and column offset of a given keyword node.
516
517 @param node reference to the keyword node
518 @type ast.keyword
519 @return tuple containing the line number and the column offset
520 @rtype tuple of (int, int)
521 """
522 if sys.version_info >= (3, 9):
523 return (node.lineno, node.col_offset)
524 else:
525 # Educated guess
526 return (
527 node.value.lineno,
528 max(0, node.value.col_offset - 1 - len(node.arg)),
529 )
530
531 def __isAddChainWithNonStr(self, node): 507 def __isAddChainWithNonStr(self, node):
532 """ 508 """
533 Private method to check, if the node is an Add with a non string argument. 509 Private method to check, if the node is an Add with a non string argument.
534 510
535 @param node reference to the binary operator node 511 @param node reference to the binary operator node

eric ide

mercurial