Pylint 是一个 python 的语法检测器,提升编程效率的同时其带来的花里胡哨的警告也是真让人看着难受,就像下面这花花绿绿的波浪线:

这些警告种类极其丰富,比如下面这样:
Method 'forward' is abstract in class 'torch.nn.modules.module' but is not overriddenPylint(W0223:abstract-method)
Formatting a regular string which could be a f-stringPylint(C0209:consider-using-f-string)
Unused import torchPylint(W0611:unused-import)
Missing function or method docstringPylint(C0116:missing-function-docstring)
。。。。。。
怎么消除这些警告?
1、如果安装了 pylint 插件

则操作如下:
在 VSCode 中依次点击 File -> Preferences -> Settings ,然后在右上角点击 Open Setting(JSON),在打开的 json 文件中添加以下语句即可:
"pylint.args": ["--errors-only"]
2、如果使用 python 自带的 lint

则在上述同样的位置添加:
"python.linting.pylintArgs": ["--errors-only"]
这篇博客介绍了如何处理Python编程时由Pylint工具产生的各种警告。通过在VSCode或Python的lint设置中添加特定参数`--errors-only`,可以仅显示错误而忽略警告。警告包括未覆盖的抽象方法、非f-string格式化字符串、未使用的导入等。按照提供的步骤配置设置,可以帮助优化编码体验,减少不必要的干扰。
3万+

被折叠的 条评论
为什么被折叠?



