--- a/eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py Sat May 01 14:27:20 2021 +0200 @@ -12,13 +12,11 @@ import re import traceback import multiprocessing - +import contextlib -try: +with contextlib.suppress(ImportError): from pyflakes.checker import Checker from pyflakes.messages import ImportStarUsed, ImportStarUsage -except ImportError: - pass VcsConflictMarkerRegExpList = ( re.compile( @@ -60,7 +58,7 @@ codestring = codestring.replace("\r\n", "\n").replace("\r", "\n") if codestring and codestring[-1] != '\n': - codestring = codestring + '\n' + codestring += '\n' return codestring @@ -207,15 +205,20 @@ Function to compile one Python source file to Python bytecode and to perform a pyflakes check. - @param filename source filename (string) - @param codestring string containing the code to compile (string) - @param checkFlakes flag indicating to do a pyflakes check (boolean) + @param filename source filename + @type str + @param codestring string containing the code to compile + @type str + @param checkFlakes flag indicating to do a pyflakes check + @type bool @param ignoreStarImportWarnings flag indicating to - ignore 'star import' warnings (boolean) + ignore 'star import' warnings + @type bool @return dictionary with the keys 'error' and 'warnings' which hold a list containing details about the error/ warnings (file name, line number, column, codestring (only at syntax errors), the message, a list with arguments for the message) + @rtype dict """ import builtins @@ -278,13 +281,11 @@ error = str(detail) return [{'error': (fn, line, 0, "", error)}] except Exception as detail: - try: + with contextlib.suppress(Exception): fn = detail.filename line = detail.lineno error = detail.msg return [{'error': (fn, line, 0, "", error)}] - except Exception: # secok - pass # pyflakes if not checkFlakes: @@ -296,29 +297,24 @@ warnings = Checker(module, filename, withDoctest=True) warnings.messages.sort(key=lambda a: a.lineno) for warning in warnings.messages: - if ignoreStarImportWarnings and ( - isinstance(warning, ImportStarUsed) or - isinstance(warning, ImportStarUsage) + if ( + ignoreStarImportWarnings and + isinstance(warning, (ImportStarUsed, ImportStarUsage)) ): continue _fn, lineno, col, message, msg_args = warning.getMessageData() lineFlags = extractLineFlags(lines[lineno - 1].strip()) - try: + with contextlib.suppress(IndexError): lineFlags += extractLineFlags(lines[lineno].strip(), flagsLine=True) - except IndexError: - pass if ( "__IGNORE_WARNING__" not in lineFlags and "noqa" not in lineFlags ): results.append((_fn, lineno, col, "", message, msg_args)) except SyntaxError as err: - if err.text.strip(): - msg = err.text.strip() - else: - msg = err.msg + msg = err.text.strip() if err.text.strip() else err.msg results.append((filename, err.lineno, 0, "FLAKES_ERROR", msg, [])) return [{'warnings': results}]