6

Python使用Flake8做代码静态检查的时候如何忽略一些比较长的语句[E501]

 3 years ago
source link: https://codechina.org/2019/09/python-flake8-line-too-long-e501/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Python使用Flake8做代码静态检查的时候如何忽略一些比较长的语句[E501] – Tinyfool的个人网站

最近开始在Visul Studio Code里面用Flake8做我的Python项目的代码静态检查,感觉不错,确实可以提升可读性。

但是在我的测试样例里面,我发现有时候我要引入一些比较长的JSON字符串,作为测试的样本,格式化然后多行太占地方,而且比较麻烦,而且里面涉及到一些长文本,折行就更麻烦了。

这个时候,Flake 8会报出一个信息:

line too long (791 > 79 characters) E501

怎么解决呢?

于是我查了一下,引入一个长字符串的情况下,如果想让某一行被Flake 8忽略,而不报警行太长,可以用 # noqa 标记来解决,把它放在行尾即可。

somejson = '''{"user_id": 1112312312,  "text":"some thing too long some thing too long some thing too long" }''' # noqa

这样的话,这句话的太长问题就会被Flake 8忽略了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK