eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

changeset 8243
cc717c2ae956
parent 8218
7c09585bd960
child 8244
ed8cb108b27b
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py	Thu Apr 15 16:52:05 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py	Thu Apr 15 18:11:24 2021 +0200
@@ -11,6 +11,7 @@
 import ast
 import sys
 import multiprocessing
+import contextlib
 
 import pycodestyle
 from Naming.NamingStyleChecker import NamingStyleChecker
@@ -287,7 +288,11 @@
     src = "".join(source)
     
     try:
-        tree = ast.parse(src, filename, 'exec')
+        if sys.version_info >= (3, 8):
+            # need the 'type_comments' parameter to include type annotations
+            tree = ast.parse(src, filename, 'exec', type_comments=True)
+        else:
+            tree = ast.parse(src, filename, 'exec')
         return None, None, tree
     except (SyntaxError, TypeError):
         exc_type, exc = sys.exc_info()[:2]
@@ -479,11 +484,9 @@
             if source:
                 code = error["code"]
                 lineFlags = extractLineFlags(source[lineno - 1].strip())
-                try:
+                with contextlib.suppress(IndexError):
                     lineFlags += extractLineFlags(source[lineno].strip(),
                                                   flagsLine=True)
-                except IndexError:
-                    pass
                 
                 if securityOk(code, lineFlags):
                     error["securityOk"] = True

eric ide

mercurial