--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyCheckSyntax.py Mon Aug 28 14:08:41 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyCheckSyntax.py Mon Aug 28 16:28:13 2023 +0200 @@ -14,6 +14,7 @@ import queue import re import traceback +import warnings with contextlib.suppress(ImportError): from pyflakes.checker import Checker @@ -243,6 +244,8 @@ @rtype dict """ if codestring: + warnings.filterwarnings("error") + errorDict = {} try: # Check for VCS conflict markers for conflictMarkerRe in VcsConflictMarkerRegExpList: @@ -298,7 +301,7 @@ fn = detail.filename line = detail.lineno or 1 error = detail.msg - return [{"error": (fn, int(line), index, code.strip(), error)}] + errorDict = {"error": (fn, int(line), index, code.strip(), error)} except ValueError as detail: try: fn = detail.filename @@ -308,13 +311,19 @@ fn = filename line = 1 error = str(detail) - return [{"error": (fn, line, 0, "", error)}] + errorDict = {"error": (fn, line, 0, "", error)} except Exception as detail: with contextlib.suppress(AttributeError): fn = detail.filename line = detail.lineno error = detail.msg - return [{"error": (fn, line, 0, "", error)}] + errorDict = {"error": (fn, line, 0, "", error)} + finally: + warnings.resetwarnings() + + # return the syntax error or warning, if one was detected + if errorDict: + return [errorDict] # pyflakes if not checkFlakes: @@ -323,17 +332,17 @@ results = [] lines = codestring.splitlines() try: - warnings = Checker( + flakesWarnings = Checker( module, filename, builtins=additionalBuiltins, withDoctest=True ) - warnings.messages.sort(key=lambda a: a.lineno) - for warning in warnings.messages: + flakesWarnings.messages.sort(key=lambda a: a.lineno) + for flakesWarning in flakesWarnings.messages: if ignoreStarImportWarnings and isinstance( - warning, (ImportStarUsed, ImportStarUsage) + flakesWarning, (ImportStarUsed, ImportStarUsage) ): continue - _fn, lineno, col, message, msg_args = warning.getMessageData() + _fn, lineno, col, message, msg_args = flakesWarning.getMessageData() lineFlags = extractLineFlags(lines[lineno - 1].strip()) with contextlib.suppress(IndexError): lineFlags += extractLineFlags(lines[lineno].strip(), flagsLine=True)