--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Thu Nov 30 11:59:40 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Thu Nov 30 16:39:46 2023 +0100 @@ -182,12 +182,6 @@ "M625", "M631", "M632", - ## Logging - "M651", - "M652", - "M653", - "M654", - "M655", ## Future statements "M701", "M702", @@ -400,7 +394,6 @@ "M632", ), ), - (self.__checkLogging, ("M651", "M652", "M653", "M654", "M655")), (self.__checkFuture, ("M701", "M702")), (self.__checkGettext, ("M711",)), (self.__checkPrintStatements, ("M801",)), @@ -1278,15 +1271,6 @@ key1.value, ) - def __checkLogging(self): - """ - Private method to check logging statements. - """ - visitor = LoggingVisitor() - visitor.visit(self.__tree) - for node, reason in visitor.violations: - self.__error(node.lineno - 1, node.col_offset, reason) - def __checkGettext(self): """ Private method to check the 'gettext' import statement. @@ -1437,7 +1421,7 @@ self.__error(node.lineno - 1, node.col_offset, "M217", node.name) ####################################################################### - ## The following method check for implicitly concatenated strings + ## The following methods check for implicitly concatenated strings. ## ## These methods are adapted from: flake8-implicit-str-concat v0.4.0 ## Original: Copyright (c) 2023 Dylan Turner @@ -1660,182 +1644,6 @@ super().generic_visit(node) -class LoggingVisitor(ast.NodeVisitor): - """ - Class implementing a node visitor to check logging statements. - """ - - LoggingLevels = { - "debug", - "critical", - "error", - "info", - "warn", - "warning", - } - - def __init__(self): - """ - Constructor - """ - super().__init__() - - self.__currentLoggingCall = None - self.__currentLoggingArgument = None - self.__currentLoggingLevel = None - self.__currentExtraKeyword = None - self.violations = [] - - def __withinLoggingStatement(self): - """ - Private method to check, if we are inside a logging statement. - - @return flag indicating we are inside a logging statement - @rtype bool - """ - return self.__currentLoggingCall is not None - - def __withinLoggingArgument(self): - """ - Private method to check, if we are inside a logging argument. - - @return flag indicating we are inside a logging argument - @rtype bool - """ - return self.__currentLoggingArgument is not None - - def __withinExtraKeyword(self, node): - """ - Private method to check, if we are inside the extra keyword. - - @param node reference to the node to be checked - @type ast.keyword - @return flag indicating we are inside the extra keyword - @rtype bool - """ - return ( - self.__currentExtraKeyword is not None - and self.__currentExtraKeyword != node - ) - - def __detectLoggingLevel(self, node): - """ - Private method to decide whether an AST Call is a logging call. - - @param node reference to the node to be processed - @type ast.Call - @return logging level - @rtype str or None - """ - with contextlib.suppress(AttributeError): - if node.func.value.id == "warnings": - return None - - if node.func.attr in LoggingVisitor.LoggingLevels: - return node.func.attr - - return None - - def __isFormatCall(self, node): - """ - Private method to check if a function call uses format. - - @param node reference to the node to be processed - @type ast.Call - @return flag indicating the function call uses format - @rtype bool - """ - try: - return node.func.attr == "format" - except AttributeError: - return False - - def visit_Call(self, node): - """ - Public method to handle a function call. - - Every logging statement and string format is expected to be a function - call. - - @param node reference to the node to be processed - @type ast.Call - """ - # we are in a logging statement - if ( - self.__withinLoggingStatement() - and self.__withinLoggingArgument() - and self.__isFormatCall(node) - ): - self.violations.append((node, "M651")) - super().generic_visit(node) - return - - loggingLevel = self.__detectLoggingLevel(node) - - if loggingLevel and self.__currentLoggingLevel is None: - self.__currentLoggingLevel = loggingLevel - - # we are in some other statement - if loggingLevel is None: - super().generic_visit(node) - return - - # we are entering a new logging statement - self.__currentLoggingCall = node - - if loggingLevel == "warn": - self.violations.append((node, "M655")) - - for index, child in enumerate(ast.iter_child_nodes(node)): - if index == 1: - self.__currentLoggingArgument = child - if index > 1 and isinstance(child, ast.keyword) and child.arg == "extra": - self.__currentExtraKeyword = child - - super().visit(child) - - self.__currentLoggingArgument = None - self.__currentExtraKeyword = None - - self.__currentLoggingCall = None - self.__currentLoggingLevel = None - - def visit_BinOp(self, node): - """ - Public method to handle binary operations while processing the first - logging argument. - - @param node reference to the node to be processed - @type ast.BinOp - """ - if self.__withinLoggingStatement() and self.__withinLoggingArgument(): - # handle percent format - if isinstance(node.op, ast.Mod): - self.violations.append((node, "M652")) - - # handle string concat - if isinstance(node.op, ast.Add): - self.violations.append((node, "M653")) - - super().generic_visit(node) - - def visit_JoinedStr(self, node): - """ - Public method to handle f-string arguments. - - @param node reference to the node to be processed - @type ast.JoinedStr - """ - if ( - self.__withinLoggingStatement() - and any(isinstance(i, ast.FormattedValue) for i in node.values) - and self.__withinLoggingArgument() - ): - self.violations.append((node, "M654")) - - super().generic_visit(node) - - ####################################################################### ## BugBearVisitor ##