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

branch
eric7
changeset 11150
73d80859079c
parent 11148
15e30f0c76a8
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Logging/LoggingVisitor.py	Thu Feb 27 09:22:15 2025 +0100
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Logging/LoggingVisitor.py	Thu Feb 27 14:42:39 2025 +0100
@@ -173,13 +173,9 @@
         if node.module == "logging":
             for alias in node.names:
                 if alias.name == "WARN":
-                    if sys.version_info >= (3, 10):
-                        lineno = alias.lineno
-                        colOffset = alias.col_offset
-                    else:
-                        lineno = node.lineno
-                        colOffset = node.col_offset
-                    self.__error(lineno - 1, colOffset, "L-109")
+                    self.__error(
+                        alias if sys.version_info >= (3, 10) else node, "L-109"
+                    )
                 if not alias.asname:
                     self.__fromImports[alias.name] = node.module
 
@@ -198,7 +194,7 @@
             and node.value.id == self.__loggingName
             and node.attr == "WARN"
         ):
-            self.__error(node.lineno - 1, node.col_offset, "L-109")
+            self.__error(node, "L-109")
 
         self.generic_visit(node)
 
@@ -223,7 +219,7 @@
                 and self.__fromImports.get("Logger") == "logging"
             )
         ) and not self.__atModuleLevel():
-            self.__error(node.lineno - 1, node.col_offset, "L-101")
+            self.__error(node, "L-101")
 
         if (
             isinstance(node.func, ast.Attribute)
@@ -236,7 +232,7 @@
             and node.func.id in _LoggerMethods
             and self.__fromImports.get(node.func.id) == "logging"
         ):
-            self.__error(node.lineno - 1, node.col_offset, "L-115")
+            self.__error(node, "L-115")
 
         if (
             self.__loggingName
@@ -263,7 +259,7 @@
                 and isinstance(node.args[0], ast.Name)
                 and node.args[0].id in self.GetLoggerNames
             ):
-                self.__error(node.args[0].lineno - 1, node.args[0].col_offset, "L-102")
+                self.__error(node.args[0], "L-102")
 
         if (
             isinstance(node.func, ast.Attribute)
@@ -277,7 +273,7 @@
 
             # L108
             if node.func.attr == "warn":
-                self.__error(node.lineno - 1, node.col_offset, "L-108")
+                self.__error(node, "L-108")
 
             # L103
             extraKeys = []
@@ -301,14 +297,12 @@
 
             for key, keyNode in extraKeys:
                 if key in _LogrecordAttributes:
-                    self.__error(
-                        keyNode.lineno - 1, keyNode.col_offset, "L-103", repr(key)
-                    )
+                    self.__error(keyNode, "L-103", repr(key))
 
             if node.func.attr == "exception":
                 # L104
                 if not excHandler:
-                    self.__error(node.lineno - 1, node.col_offset, "L-104")
+                    self.__error(node, "L-104")
 
                 if any((excInfo := kw).arg == "exc_info" for kw in node.keywords):
                     # L106
@@ -319,14 +313,14 @@
                         and isinstance(excInfo.value, ast.Name)
                         and excInfo.value.id == excHandler.name
                     ):
-                        self.__error(excInfo.lineno - 1, excInfo.col_offset, "L-106")
+                        self.__error(excInfo, "L-106")
 
                     # L107
                     elif (
                         isinstance(excInfo.value, ast.Constant)
                         and not excInfo.value.value
                     ):
-                        self.__error(excInfo.lineno - 1, excInfo.col_offset, "L-107")
+                        self.__error(excInfo, "L-107")
 
             # L105
             elif node.func.attr == "error" and excHandler is not None:
@@ -343,7 +337,7 @@
                     rewritable = True
 
                 if rewritable:
-                    self.__error(node.lineno - 1, node.col_offset, "L-105")
+                    self.__error(node, "L-105")
 
             # L114
             elif (
@@ -352,7 +346,7 @@
                 and isinstance(excInfo.value, ast.Constant)
                 and excInfo.value.value
             ):
-                self.__error(excInfo.lineno - 1, excInfo.col_offset, "L-114")
+                self.__error(excInfo, "L-114")
 
             # L110
             if (
@@ -362,7 +356,7 @@
                 and excHandler is not None
                 and node.args[0].id == excHandler.name
             ):
-                self.__error(node.args[0].lineno - 1, node.args[0].col_offset, "L-110")
+                self.__error(node.args[0], "L-110")
 
             msgArgKwarg = False
             if node.func.attr == "log" and len(node.args) >= 2:
@@ -378,7 +372,7 @@
 
             # L111
             if isinstance(msgArg, ast.JoinedStr):
-                self.__error(msgArg.lineno - 1, msgArg.col_offset, "L-111a")
+                self.__error(msgArg, "L-111a")
             elif (
                 isinstance(msgArg, ast.Call)
                 and isinstance(msgArg.func, ast.Attribute)
@@ -386,16 +380,16 @@
                 and isinstance(msgArg.func.value.value, str)
                 and msgArg.func.attr == "format"
             ):
-                self.__error(msgArg.lineno - 1, msgArg.col_offset, "L-111b")
+                self.__error(msgArg, "L-111b")
             elif (
                 isinstance(msgArg, ast.BinOp)
                 and isinstance(msgArg.op, ast.Mod)
                 and isinstance(msgArg.left, ast.Constant)
                 and isinstance(msgArg.left.value, str)
             ):
-                self.__error(msgArg.lineno - 1, msgArg.col_offset, "L-111c")
+                self.__error(msgArg, "L-111c")
             elif isinstance(msgArg, ast.BinOp) and self.__isAddChainWithNonStr(msgArg):
-                self.__error(msgArg.lineno - 1, msgArg.col_offset, "L-111d")
+                self.__error(msgArg, "L-111d")
 
             # L112
             if (
@@ -441,20 +435,12 @@
             # L113
             given = {cast(ast.Constant, k).value for k in dictNode.keys}
             if missing := modnames - given:
-                self.__error(
-                    msgArg.lineno - 1,
-                    msgArg.col_offset,
-                    "L-113a",  # missing keys
-                    ", ".join([repr(k) for k in missing]),
-                )
+                # missing keys
+                self.__error(msgArg, "L-113a", ", ".join([repr(k) for k in missing]))
 
             if missing := given - modnames:
-                self.__error(
-                    msgArg.lineno - 1,
-                    msgArg.col_offset,
-                    "L-113b",  # unreferenced keys
-                    ", ".join([repr(k) for k in missing]),
-                )
+                # unreferenced keys
+                self.__error(msgArg, "L-113b", ", ".join([repr(k) for k in missing]))
 
             return
 
@@ -467,14 +453,7 @@
         argCount = len(node.args) - 1 - (node.func.attr == "log")
 
         if modposCount > 0 and modposCount != argCount:
-            self.__error(
-                msgArg.lineno - 1,
-                msgArg.col_offset,
-                "L-112",
-                modposCount,
-                "'%'",  # noqa: M-601
-                argCount,
-            )
+            self.__error(msgArg, "L-112", modposCount, "'%'", argCount)  # noqa: M-601
             return
 
     def __atModuleLevel(self):

eric ide

mercurial