A lot of our modules start with:
try:
import json
except ImportError:
from django.utils import simplejson as json # Python 2.4 fallback.
Here is a monkey patch for pyflakes that adds a # bypass_pyflakes
comment option.
#!/usr/bin/env python
from pyflakes.scripts import pyflakes
from pyflakes.checker import Checker
def report_with_bypass(self, messageClass, *args, **kwargs):
text_lineno = args[0] - 1
with open(self.filename, 'r') as code:
if code.readlines()[text_lineno].find('bypass_pyflakes') >= 0:
return
self.messages.append(messageClass(self.filename, *args, **kwargs))
# monkey patch checker to support bypass
Checker.report = report_with_bypass
pyflakes.main()
If you save this as bypass_pyflakes.py
, then you can invoke it as python bypass_pyflakes.py myfile.py
.
http://chase-seibert.github.com/blog/2013/01/11/bypass_pyflakes.html