eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py

branch
maintenance
changeset 7642
72721823d453
parent 7639
422fd05e9c91
child 7900
72b88fb20261
child 7924
8a96736d465e
diff -r f7cb83647621 -r 72721823d453 eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py
--- a/eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Sun May 31 17:26:46 2020 +0200
+++ b/eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Sat Jul 04 11:45:34 2020 +0200
@@ -4,17 +4,12 @@
 #
 
 """
-Module implementing the syntax check for Python 2/3.
+Module implementing the syntax check for Python 3.
 """
 
-try:  # Only for Py2
-    import Queue as queue
-except ImportError:
-    import queue
-
+import queue
 import ast
 import re
-import sys
 import traceback
 import multiprocessing
 
@@ -66,13 +61,6 @@
 
     if codestring and codestring[-1] != '\n':
         codestring = codestring + '\n'
-
-    # Check type for py2: if not str it's unicode
-    if sys.version_info[0] == 2:
-        try:
-            codestring = codestring.encode('utf-8')
-        except UnicodeError:
-            pass
     
     return codestring
 
@@ -229,19 +217,9 @@
             (file name, line number, column, codestring (only at syntax
             errors), the message, a list with arguments for the message)
     """
-    try:
-        import builtins
-    except ImportError:
-        import __builtin__ as builtins        # __IGNORE_WARNING__
+    import builtins
     
     try:
-        if sys.version_info[0] == 2:
-            file_enc = filename.encode(sys.getfilesystemencoding())
-        else:
-            file_enc = filename
-        
-        # It also encode the code back to avoid 'Encoding declaration in
-        # unicode string' exception on Python2
         codestring = normalizeCode(codestring)
         
         # Check for VCS conflict markers
@@ -251,7 +229,7 @@
                 start, i = conflict.span()
                 lineindex = 1 + codestring.count("\n", 0, start)
                 return [{'error':
-                         (file_enc, lineindex, 0, "",
+                         (filename, lineindex, 0, "",
                           "VCS conflict marker found")
                          }]
         
@@ -261,18 +239,16 @@
             except ImportError:
                 return [{'error': (filename, 0, 0, '',
                         'Quixote plugin not found.')}]
-            template = quixote.ptl_compile.Template(codestring, file_enc)
+            template = quixote.ptl_compile.Template(codestring, filename)
             template.compile()
         else:
             module = builtins.compile(
-                codestring, file_enc, 'exec', ast.PyCF_ONLY_AST)
+                codestring, filename, 'exec', ast.PyCF_ONLY_AST)
     except SyntaxError as detail:
         index = 0
         code = ""
         error = ""
         lines = traceback.format_exception_only(SyntaxError, detail)
-        if sys.version_info[0] == 2:
-            lines = [x.decode(sys.getfilesystemencoding()) for x in lines]
         match = re.match(r'\s*File "(.+)", line (\d+)',
                          lines[0].replace('<string>', filename))
         if match is not None:
@@ -307,7 +283,7 @@
             line = detail.lineno
             error = detail.msg
             return [{'error': (fn, line, 0, "", error)}]
-        except Exception:
+        except Exception:           # secok
             pass
     
     # pyflakes
@@ -346,6 +322,3 @@
         results.append((filename, err.lineno, 0, "FLAKES_ERROR", msg, []))
     
     return [{'warnings': results}]
-
-#
-# eflag: noqa = M702

eric ide

mercurial