Linting Python:什么是好的?
是否有任何好的模块可以针对您的代码运行以捕获编码错误?我希望 pylint 在使用函数默认参数时发现错误 像这样< /a>:
>>> def spam(eggs=[]):
... eggs.append("spam")
... return eggs
但很失望地发现它们没有被报告。我正在寻找 PEP8 格式之外的东西。
Are there any good modules that you can run against your code to catch coding errors? I expected pylint to catch mistakes in the use of default arguments to functions like this:
>>> def spam(eggs=[]):
... eggs.append("spam")
... return eggs
but was disappointed to find them unreported. I am looking for something beyond PEP8 formatting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试了第一个示例,PyLint 0.18.1 给了我警告:
I tried the first example and PyLint 0.18.1 gave me the warning:
如果您想要这样做,那么这不是代码中的错误。然而,正如接受的答案中所指定的,空列表是一个“危险”的默认值,因为它很容易引入难以发现的问题。
That is not an error in your code if that is what you want to do. However, as specified in the accepted answer, an empty list is a "dangerous" default value in that it is easy to introduce hard-to-find problems.