Commits

Waldemar Kornewald  committed 1015580

ignore redefined functions if they are decorated

  • Participants
  • Parent commits 8c827de

Comments (0)

Files changed (1)

File hghooks/checkers.py

 import pyflakes.checker
 import sys
 
+from pyflakes.messages import RedefinedFunction
+
 re_options = re.IGNORECASE | re.MULTILINE | re.DOTALL
 
 pdb_catcher = re.compile(r'^[^#]*pdb\.set_trace\(\)', re_options)
         w = pyflakes.checker.Checker(tree, filename)
 
         lines = data.split('\n')
-        # Ignoring lines with a "pyflakes:ignore" comment at the end
+        # Ignoring lines with a "pyflakes:ignore" comment at the end and
+        # RedefinedFunction messages for decorated functions
         messages = [message for message in w.messages
-                    if lines[message.lineno - 1].find('pyflakes:ignore') < 0]
+                    if 'pyflakes:ignore' not in lines[message.lineno - 1] and
+                       not (isinstance(message, RedefinedFunction) and
+                            lines[message.lineno - 1].strip().startswith('@'))]
         messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
         for warning in messages:
             print warning