我们的很多模块都是这样开始的:
try:
import json
except ImportError:
from django.utils import simplejson as json # Python 2.4 fallback.
...and这是整个文件中唯一的Pyflake警告:
foo/bar.py:14: redefinition of unused 'json' from line 12
我怎样才能让Pyflake忽略它呢?
(通常我会去读the docs,但是链接断了。如果没有人知道答案,我将只读源代码。)
发布于 2012-05-09 05:22:31
如果您可以使用flake8 -它包装了pyflakes和pep8检查器-一行结束于
# NOQA
(其中的空格很重要--在代码末尾和#
之间有两个空格,在它和NOQA
文本之间有一个空格)将告诉检查器忽略该行上的任何错误。
发布于 2012-08-25 19:01:31
我知道这个问题在一段时间前就被质疑了,并且已经得到了回答。
但我想添加我通常使用的内容:
try:
import json
assert json # silence pyflakes
except ImportError:
from django.utils import simplejson as json # Python 2.4 fallback.
发布于 2013-01-12 07:25:16
这是一个添加了# bypass_pyflakes
注释选项的pyflakes的猴子补丁。
bypass_pyflakes.py
#!/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()
如果将其另存为bypass_pyflakes.py
,则可以作为python bypass_pyflakes.py myfile.py
调用它。
http://chase-seibert.github.com/blog/2013/01/11/bypass_pyflakes.html
https://stackoverflow.com/questions/5033727
复制相似问题