Commits

Anonymous committed d618ced

fixed support for latest pyflakes (which uses the ast module instead of compiler)

Comments (0)

Files changed (1)

hghooks/checkers.py

 # You should have received a copy of the GNU Lesser General Public License
 # along with hghooks.  If not, see <http://www.gnu.org/licenses/>.
 
-import compiler
+import ast
 import re
 import os
 import pep8
     Code adapted from http://djangosnippets.org/snippets/1762/ which is adapted
     from pyflakes.scripts.pyflakes.check function.
     """
-    # Since compiler.parse does not reliably report syntax errors, use the
-    # built in compiler first to detect those.
     try:
-        try:
-            compile(data, filename, "exec")
-        except MemoryError:
-            # Python 2.4 will raise MemoryError if the source can't be
-            # decoded.
-            if sys.version_info[:2] == (2, 4):
-                raise SyntaxError(None)
-            raise
+        compile(data, filename, 'exec')
     except (SyntaxError, IndentationError), value:
         msg = value.args[0]
 
     else:
         # Okay, it's syntactically valid.  Now parse it into an ast and check
         # it.
-        tree = compiler.parse(data)
+        tree = ast.parse(data)
         w = pyflakes.checker.Checker(tree, filename)
 
         lines = data.split('\n')
 def pyflakes_checker(files_to_check):
     return sum([pyflakes_check(data, filename)
                 for filename, data in files_to_check.items()])
-