Wed, 19 Feb 2025 15:09:52 +0100
Fixed a few issues in the code style checker.
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -81,7 +81,7 @@ @type dict """ self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -135,7 +135,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Async/AsyncChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Async/AsyncChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -24,6 +24,7 @@ "ASY104", "ASY105", ] + Prefix = "ASY" def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): """ @@ -46,10 +47,8 @@ @param args dictionary of arguments for the various checks @type dict """ - self.__select = tuple(select) - self.__ignore = ( - ("",) if select else tuple(x for x in ignore if x.startswith("ASY")) - ) + self.__select = tuple(x for x in select if x.startswith(AsyncChecker.Prefix)) + self.__ignore = tuple(x for x in ignore if x.startswith(AsyncChecker.Prefix)) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -84,7 +83,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -26,13 +26,11 @@ from NameOrder.NameOrderChecker import NameOrderChecker from Naming.NamingStyleChecker import NamingStyleChecker from PathLib.PathlibChecker import PathlibChecker +from Pydantic.PydanticChecker import PydanticChecker from Security.SecurityChecker import SecurityChecker from Simplify.SimplifyChecker import SimplifyChecker from Unused.UnusedChecker import UnusedChecker -# register the name checker -pycodestyle.register_check(NamingStyleChecker, NamingStyleChecker.Codes) - def initService(): """ @@ -459,8 +457,8 @@ styleGuide = pycodestyle.StyleGuide( reporter=CodeStyleCheckerReport, repeat=repeatMessages, - select=select, - ignore=ignore, + select=[], + ignore=[x for x in ignore if x.startswith(("E", "W"))], max_line_length=maxLineLength, max_doc_length=maxDocLineLength, hang_closing=hangClosing, @@ -555,6 +553,21 @@ stats.update(importsChecker.counters) errors += importsChecker.errors + # check naming style + namingStyleChecker = NamingStyleChecker( + source, + filename, + tree, + select, + ignore, + [], + repeatMessages, + {}, # no arguments yet + ) + namingStyleChecker.run() + stats.update(namingStyleChecker.counters) + errors += namingStyleChecker.errors + # check name ordering nameOrderChecker = NameOrderChecker( source, @@ -615,6 +628,21 @@ stats.update(loggingChecker.counters) errors += loggingChecker.errors + # check 'pydantic' related topics + pydanticChecker = PydanticChecker( + source, + filename, + tree, + select, + ignore, + [], + repeatMessages, + {}, # no arguments yet + ) + pydanticChecker.run() + stats.update(pydanticChecker.counters) + errors += pydanticChecker.errors + elif syntaxError: errors = [syntaxError] stats.update(syntaxStats)
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py Wed Feb 19 15:09:52 2025 +0100 @@ -93,6 +93,7 @@ "N": QCoreApplication.translate("CheckerCategories", "Naming"), "NO": QCoreApplication.translate("CheckerCategories", "Name Order"), "P": QCoreApplication.translate("CheckerCategories", "'pathlib' Usage"), + "PYD": QCoreApplication.translate("CheckerCategories", "'pydantic' Usage"), "S": QCoreApplication.translate("CheckerCategories", "Security"), "U": QCoreApplication.translate("CheckerCategories", "Unused"), "W": QCoreApplication.translate("CheckerCategories", "Warnings"), @@ -794,8 +795,6 @@ self.__data["UnusedChecker"]["IgnoreDunderGlobals"] ) - self.__cleanupData() - def __prepareProgress(self): """ Private method to prepare the progress tab for the next run. @@ -879,7 +878,6 @@ self.__errorItem = None self.__resetStatistics() self.__clearErrors(self.files) - self.__cleanupData() self.__prepareProgress() # disable updates of the list for speed @@ -893,7 +891,7 @@ # extract the configuration values excludeMessages = self.__assembleExcludeMessages() - includeMessages = self.includeMessagesEdit.text() + includeMessages = self.__assembleIncludeMessages() repeatMessages = self.repeatCheckBox.isChecked() fixCodes = self.fixIssuesEdit.text() noFixCodes = self.noFixIssuesEdit.text() @@ -1373,8 +1371,6 @@ """ Private slot to start a code style check run. """ - self.__cleanupData() - if self.__forProject: data = { "EnabledCheckerCategories": self.__getCategories(True), @@ -2200,8 +2196,6 @@ ) ) - self.__cleanupData() - @pyqtSlot() def on_storeDefaultButton_clicked(self): """ @@ -2916,7 +2910,7 @@ disabledCategories = self.__getCategories(False) if excludeMessages and disabledCategories: - return disabledCategories + "," + excludeMessages + return disabledCategories + ", " + excludeMessages elif disabledCategories: return disabledCategories elif excludeMessages: @@ -2924,30 +2918,24 @@ else: return "" - def __cleanupData(self): + def __assembleIncludeMessages(self): """ - Private method to clean the loaded/entered data of redundant entries. + Private method to assemble the list of included checks. + + @return list of included checks as a comma separated string. + @rtype str """ - # Migrate single letter exclude messages to disabled checker categories - # and delete them from exclude messages - excludedMessages = [ - m.strip() for m in self.excludeMessagesEdit.text().split(",") if bool(m) - ] - excludedMessageCategories = [c for c in excludedMessages if len(c) == 1] - enabledCheckers = self.__getCategories(True, asList=True) - for category in excludedMessageCategories: - if category in enabledCheckers: - enabledCheckers.remove(category) - excludedMessages.remove(category) + includeMessages = self.includeMessagesEdit.text() + enabledCategories = self.__getCategories(True) - # Remove excluded messages of an already excluded category - disabledCheckers = self.__getCategories(False, asList=True) - for message in excludedMessages[:]: - if message[0] in disabledCheckers: - excludedMessages.remove(message) - - self.excludeMessagesEdit.setText(",".join(excludedMessages)) - self.__initCategoriesList(",".join(enabledCheckers)) + if includeMessages and enabledCategories: + return enabledCategories + ", " + includeMessages + elif enabledCategories: + return enabledCategories + elif includeMessages: + return includeMessages + else: + return "" def __initCommentedCodeCheckerWhiteList(self, whitelist): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -45,7 +45,7 @@ self.__source = source[:] self.__tree = copy.deepcopy(tree) self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__args = args self.__defaultArgs = { @@ -79,7 +79,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -222,7 +222,7 @@ @type str """ self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__maxLineLength = maxLineLength @@ -348,7 +348,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Imports/ImportsChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Imports/ImportsChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -51,7 +51,7 @@ @type dict """ self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -84,7 +84,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Logging/LoggingChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Logging/LoggingChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -55,8 +55,8 @@ @param args dictionary of arguments for the various checks @type dict """ - self.__select = tuple(select) # noqa: M188 - self.__ignore = ("",) if select else tuple(ignore) # noqa: M188 + self.__select = tuple(select) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -107,7 +107,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -283,7 +283,7 @@ @type dict """ self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -485,7 +485,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/NameOrder/NameOrderChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/NameOrder/NameOrderChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -28,6 +28,7 @@ "NO104", "NO105", ] + Prefix = "NO" def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): """ @@ -50,8 +51,12 @@ @param args dictionary of arguments for the various checks @type dict """ - self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__select = tuple( + x for x in select if x.startswith(NameOrderChecker.Prefix) + ) + self.__ignore = tuple( + x for x in ignore if x.startswith(NameOrderChecker.Prefix) + ) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -91,7 +96,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Naming/NamingStyleChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Naming/NamingStyleChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -9,6 +9,7 @@ import ast import collections +import copy import functools import os @@ -18,6 +19,7 @@ ast.AsyncFunctionDef = ast.FunctionDef +# TODO: change this to a checker like the others class NamingStyleChecker: """ Class implementing a checker for naming conventions. @@ -45,20 +47,43 @@ "N831", ] - def __init__(self, tree, filename, options): + def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): """ - Constructor (according to 'extended' pycodestyle.py API) + Constructor - @param tree AST tree of the source file - @type ast.AST + @param source source code to be checked + @type list of str @param filename name of the source file @type str - @param options options as parsed by pycodestyle.StyleGuide - @type optparse.Option + @param tree AST tree of the source code + @type ast.Module + @param select list of selected codes + @type list of str + @param ignore list of codes to be ignored + @type list of str + @param expected list of expected codes + @type list of str + @param repeat flag indicating to report each occurrence of a code + @type bool + @param args dictionary of arguments for the various checks + @type dict """ + self.__select = tuple(select) + self.__ignore = tuple(ignore) + self.__expected = expected[:] + self.__repeat = repeat + self.__filename = filename + self.__source = source[:] + self.__tree = copy.deepcopy(tree) + self.__args = args + self.__parents = collections.deque() - self.__tree = tree - self.__filename = filename + + # statistics counters + self.counters = {} + + # collection of detected errors + self.errors = [] self.__checkersWithCodes = { "classdef": [ @@ -99,14 +124,74 @@ (self.__checkImportAs, ("N811", "N812", "N813", "N814", "N815")), ] - self.__checkers = {} + self.__checkers = collections.defaultdict(list) for key, checkers in self.__checkersWithCodes.items(): for checker, codes in checkers: - if any(not (code and options.ignore_code(code)) for code in codes): - if key not in self.__checkers: - self.__checkers[key] = [] + if any(not (code and self.__ignoreCode(code)) for code in codes): self.__checkers[key].append(checker) + def __ignoreCode(self, code): + """ + Private method to check if the message code should be ignored. + + @param code message code to check for + @type str + @return flag indicating to ignore the given code + @rtype bool + """ + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) + + def __error(self, node, code): + """ + Private method to build the error information. + + @param node AST node to report an error for + @type ast.AST + @param code error code to report + @type str + """ + if self.__ignoreCode(code): + return + + if isinstance(node, ast.Module): + lineno = 0 + offset = 0 + else: + lineno = node.lineno + offset = node.col_offset + if isinstance(node, ast.ClassDef): + lineno += len(node.decorator_list) + offset += 6 + elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): + lineno += len(node.decorator_list) + offset += 4 + + # record the issue with one based line number + errorInfo = { + "file": self.__filename, + "line": lineno, + "offset": offset, + "code": code, + "args": [], + } + + if errorInfo not in self.errors: + # this issue was not seen before + if code in self.counters: + self.counters[code] += 1 + else: + self.counters[code] = 1 + + # Don't care about expected codes + if code in self.__expected: + return + + if code and (self.counters[code] == 1 or self.__repeat): + self.errors.append(errorInfo) + def run(self): """ Public method run by the pycodestyle.py checker. @@ -126,13 +211,11 @@ @param node AST tree node to scan @type ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ - yield from self.__visitNode(node) + self.__visitNode(node) self.__parents.append(node) for child in ast.iter_child_nodes(node): - yield from self.__visitTree(child) + self.__visitTree(child) self.__parents.pop() def __visitNode(self, node): @@ -141,8 +224,6 @@ @param node AST tree node to inspect @type ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ if isinstance(node, ast.ClassDef): self.__tagClassFunctions(node) @@ -152,8 +233,7 @@ checkerName = node.__class__.__name__.lower() if checkerName in self.__checkers: for checker in self.__checkers[checkerName]: - for error in checker(node, self.__parents): - yield error + (self.__checkers[checkerName],) + checker(node, self.__parents) def __tagClassFunctions(self, classNode): """ @@ -233,31 +313,6 @@ kwOnly = [arg.arg for arg in node.args.kwonlyargs] return posArgs + kwOnly - def __error(self, node, code): - """ - Private method to build the error information. - - @param node AST node to report an error for - @type ast.AST - @param code error code to report - @type str - @return tuple giving line number, offset within line and error code - @rtype tuple of (int, int, str) - """ - if isinstance(node, ast.Module): - lineno = 0 - offset = 0 - else: - lineno = node.lineno - offset = node.col_offset - if isinstance(node, ast.ClassDef): - lineno += len(node.decorator_list) - offset += 6 - elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): - lineno += len(node.decorator_list) - offset += 4 - return (lineno, offset, code) - def __isNameToBeAvoided(self, name): """ Private method to check, if the given name should be avoided. @@ -277,19 +332,17 @@ @type ast.Ast @param _parents list of parent nodes (unused) @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ if isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)): name = node.name if self.__isNameToBeAvoided(name): - yield self.__error(node, "N831") + self.__error(node, "N831") elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): argNames = self.__getArgNames(node) for arg in argNames: if self.__isNameToBeAvoided(arg): - yield self.__error(node, "N831") + self.__error(node, "N831") elif isinstance(node, (ast.Assign, ast.NamedExpr, ast.AnnAssign)): if isinstance(node, ast.Assign): @@ -300,14 +353,14 @@ if isinstance(target, ast.Name): name = target.id if bool(name) and self.__isNameToBeAvoided(name): - yield self.__error(node, "N831") + self.__error(node, "N831") elif isinstance(target, (ast.Tuple, ast.List)): for element in target.elts: if isinstance(element, ast.Name): name = element.id if bool(name) and self.__isNameToBeAvoided(name): - yield self.__error(node, "N831") + self.__error(node, "N831") def __getClassdef(self, name, parents): """ @@ -366,17 +419,15 @@ @type ast.ClassDef @param parents list of parent nodes @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ name = node.name strippedName = name.strip("_") if not strippedName[:1].isupper() or "_" in strippedName: - yield self.__error(node, "N801") + self.__error(node, "N801") superClasses = self.__superClassNames(name, parents) if "Exception" in superClasses and not name.endswith("Error"): - yield self.__error(node, "N818") + self.__error(node, "N818") def __checkFunctionName(self, node, _parents): """ @@ -393,8 +444,6 @@ @type ast.FunctionDef or ast.AsynFunctionDef @param _parents list of parent nodes (unused) @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ functionType = getattr(node, "function_type", "function") name = node.name @@ -403,9 +452,9 @@ return if name.lower() != name: - yield self.__error(node, "N802") + self.__error(node, "N802") if functionType == "function" and name[:2] == "__" and name[-2:] == "__": - yield self.__error(node, "N809") + self.__error(node, "N809") def __checkFunctionArgumentNames(self, node, _parents): """ @@ -420,18 +469,16 @@ @type ast.FunctionDef or ast.AsynFunctionDef @param _parents list of parent nodes (unused) @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ if node.args.kwarg is not None: kwarg = node.args.kwarg.arg if kwarg.lower() != kwarg: - yield self.__error(node, "N803") + self.__error(node, "N803") elif node.args.vararg is not None: vararg = node.args.vararg.arg if vararg.lower() != vararg: - yield self.__error(node, "N803") + self.__error(node, "N803") else: argNames = self.__getArgNames(node) @@ -439,19 +486,19 @@ if not argNames: if functionType == "method": - yield self.__error(node, "N805") + self.__error(node, "N805") elif functionType == "classmethod": - yield self.__error(node, "N804") + self.__error(node, "N804") elif functionType == "method" and argNames[0] != "self": - yield self.__error(node, "N805") + self.__error(node, "N805") elif functionType == "classmethod" and argNames[0] != "cls": - yield self.__error(node, "N804") + self.__error(node, "N804") elif functionType == "staticmethod" and argNames[0] in ("cls", "self"): - yield self.__error(node, "N806") + self.__error(node, "N806") for arg in argNames: if arg.lower() != arg: - yield self.__error(node, "N803") + self.__error(node, "N803") break def __checkVariableNames(self, node, parents): @@ -465,35 +512,33 @@ @type ast.AST @param parents list of parent nodes @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ nodeType = type(node) if nodeType is ast.Assign: if self.__isNamedTupel(node.value): return for target in node.targets: - yield from self.__findVariableNameErrors(target, parents) + self.__findVariableNameErrors(target, parents) elif nodeType in (ast.NamedExpr, ast.AnnAssign): if self.__isNamedTupel(node.value): return - yield from self.__findVariableNameErrors(node.target, parents) + self.__findVariableNameErrors(node.target, parents) elif nodeType in (ast.With, ast.AsyncWith): for item in node.items: - yield from self.__findVariableNameErrors(item.optional_vars, parents) + self.__findVariableNameErrors(item.optional_vars, parents) elif nodeType in (ast.For, ast.AsyncFor): - yield from self.__findVariableNameErrors(node.target, parents) + self.__findVariableNameErrors(node.target, parents) elif nodeType is ast.ExceptHandler: if node.name: - yield from self.__findVariableNameErrors(node, parents) + self.__findVariableNameErrors(node, parents) elif nodeType in (ast.GeneratorExp, ast.ListComp, ast.DictComp, ast.SetComp): for gen in node.generators: - yield from self.__findVariableNameErrors(gen.target, parents) + self.__findVariableNameErrors(gen.target, parents) def __findVariableNameErrors(self, assignmentTarget, parents): """ @@ -503,8 +548,6 @@ @type ast.Name, ast.Tuple, ast.List or ast.ExceptHandler @param parents list of parent nodes @type ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ for parentFunc in reversed(parents): if isinstance(parentFunc, ast.ClassDef): @@ -518,7 +561,7 @@ for name in self.__extractNames(assignmentTarget): errorCode = checker(name) if errorCode: - yield self.__error(assignmentTarget, errorCode) + self.__error(assignmentTarget, errorCode) def __extractNames(self, assignmentTarget): """ @@ -629,19 +672,17 @@ @type ast.AST @param _parents list of parent nodes (unused) @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ if self.__filename: moduleName = os.path.splitext(os.path.basename(self.__filename))[0] if moduleName.lower() != moduleName: - yield self.__error(node, "N807") + self.__error(node, "N807") if moduleName == "__init__": # we got a package packageName = os.path.split(os.path.dirname(self.__filename))[1] if packageName.lower() != packageName: - yield self.__error(node, "N808") + self.__error(node, "N808") def __checkImportAs(self, node, _parents): """ @@ -652,8 +693,6 @@ @type ast.Import @param _parents list of parent nodes (unused) @type list of ast.AST - @yield tuple giving line number, offset within line and error code - @ytype tuple of (int, int, str) """ for name in node.names: asname = name.asname @@ -663,14 +702,14 @@ originalName = name.name if originalName.isupper(): if not asname.isupper(): - yield self.__error(node, "N811") + self.__error(node, "N811") elif originalName.islower(): if asname.lower() != asname: - yield self.__error(node, "N812") + self.__error(node, "N812") elif asname.islower(): - yield self.__error(node, "N813") + self.__error(node, "N813") elif asname.isupper(): if "".join(filter(str.isupper, originalName)) == asname: - yield self.__error(node, "N815") + self.__error(node, "N815") else: - yield self.__error(node, "N814") + self.__error(node, "N814")
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -132,7 +132,7 @@ @type bool """ self.__select = tuple(selected) - self.__ignore = ("",) if selected else tuple(ignored) + self.__ignore = tuple(ignored) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -156,7 +156,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -140,7 +140,7 @@ @type dict """ self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -171,7 +171,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def reportError(self, lineNumber, offset, code, severity, confidence, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -100,7 +100,7 @@ @type bool """ self.__select = tuple(selected) - self.__ignore = ("",) if selected else tuple(ignored) + self.__ignore = tuple(ignored) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -124,7 +124,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Unused/UnusedChecker.py Mon Feb 17 17:09:25 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Unused/UnusedChecker.py Wed Feb 19 15:09:52 2025 +0100 @@ -49,7 +49,7 @@ @type dict """ self.__select = tuple(select) - self.__ignore = ("",) if select else tuple(ignore) + self.__ignore = tuple(ignore) self.__expected = expected[:] self.__repeat = repeat self.__filename = filename @@ -82,7 +82,10 @@ @return flag indicating to ignore the given code @rtype bool """ - return code.startswith(self.__ignore) and not code.startswith(self.__select) + return ( + code in self.__ignore + or (code.startswith(self.__ignore) and not code.startswith(self.__select)) + ) def __error(self, lineNumber, offset, code, *args): """