eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py

changeset 8198
1c765dc90c21
parent 8166
bd5cd5858503
child 8207
d359172d11be
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py	Sat Apr 03 15:09:56 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py	Sat Apr 03 16:02:33 2021 +0200
@@ -9,7 +9,7 @@
 """
 
 import ast
-import sys
+import copy
 
 
 class PathlibChecker(object):
@@ -65,7 +65,8 @@
         "py.path.local": "P401",
     }
     
-    def __init__(self, source, filename, selected, ignored, expected, repeat):
+    def __init__(self, source, filename, tree, selected, ignored, expected,
+                 repeat):
         """
         Constructor
         
@@ -73,6 +74,8 @@
         @type list of str
         @param filename name of the source file
         @type str
+        @param tree AST tree of the source code
+        @type ast.Module
         @param selected list of selected codes
         @type list of str
         @param ignored list of codes to be ignored
@@ -88,6 +91,7 @@
         self.__repeat = repeat
         self.__filename = filename
         self.__source = source[:]
+        self.__tree = copy.deepcopy(tree)
         
         # statistics counters
         self.counters = {}
@@ -147,29 +151,6 @@
                 }
             )
     
-    def __reportInvalidSyntax(self):
-        """
-        Private method to report a syntax error.
-        """
-        exc_type, exc = sys.exc_info()[:2]
-        if len(exc.args) > 1:
-            offset = exc.args[1]
-            if len(offset) > 2:
-                offset = offset[1:3]
-        else:
-            offset = (1, 0)
-        self.__error(offset[0] - 1, offset[1] or 0,
-                     'M901', exc_type.__name__, exc.args[0])
-    
-    def __generateTree(self):
-        """
-        Private method to generate an AST for our source.
-        
-        @return generated AST
-        @rtype ast.AST
-        """
-        return ast.parse("".join(self.__source), self.__filename)
-    
     def run(self):
         """
         Public method to check the given source against functions
@@ -183,12 +164,6 @@
             # don't do anything, if no codes were selected
             return
         
-        try:
-            self.__tree = self.__generateTree()
-        except (SyntaxError, TypeError):
-            self.__reportInvalidSyntax()
-            return
-        
         visitor = PathlibVisitor(self.__checkForReplacement)
         visitor.visit(self.__tree)
     

eric ide

mercurial