Commits

Ian Cordasco committed d6519dd

Add error numbers to pyflakes messages

  • Participants
  • Parent commits ca62c8f
  • Branches pyflakes

Comments (0)

Files changed (1)

 
 
 error_mapping = {
-    'W402': messages.UnusedImport,
-    'W403': messages.ImportShadowedByLoopVar,
-    'W404': messages.ImportStarUsed,
-    'W405': messages.LateFutureImport,
+    'W402': (messages.UnusedImport,),
+    'W403': (messages.ImportShadowedByLoopVar,),
+    'W404': (messages.ImportStarUsed,),
+    'W405': (messages.LateFutureImport,),
     'W801': (messages.RedefinedWhileUnused,
              messages.RedefinedInListComp,),
-    'W802': messages.UndefinedName,
-    'W803': messages.UndefinedExport,
+    'W802': (messages.UndefinedName,),
+    'W803': (messages.UndefinedExport,),
     'W804': (messages.UndefinedLocal,
              messages.UnusedVariable,),
-    'W805': messages.DuplicateArgument,
-    'W806': messages.Redefined,
+    'W805': (messages.DuplicateArgument,),
+    'W806': (messages.Redefined,),
 }
 
 
 class Flake8Reporter(reporter.Reporter):
     """Our own instance of a Reporter so that we can silence some messages."""
-    #class_mapping = dict((k, c) for (c, v) in error_mapping.items() for k in 
-    #v)
+    class_mapping = dict((k, c) for (c, v) in error_mapping.items() for k in v)
     def __init__(self, ignore=None):
         super(Flake8Reporter, self).__init__(sys.stdout, sys.stderr)
         self.ignore = ignore or []
         if (any(isinstance(message, c) for c in classes) or
                 skip_warning(message)):
             return
+        m = self.to_str(message)
+        i = m.rfind(':') + 1
+        message = '{0} {1}{2}'.format(
+            m[:i], self.class_mapping[message.__class__], m[i:]
+        )
 
         super(Flake8Reporter, self).flake(message)
+
+    def to_str(self, message):
+        try:
+            return unicode(message)
+        except NameError:
+            return str(message)