Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有任何好的模块可以针对您的代码运行以捕获编码错误?我希望 pylint 能够在使用默认参数的函数中发现错误,如下所示:
>>> def spam(eggs=[]): ... eggs.append("spam") ... return eggs
但很失望地发现他们没有报告。我正在寻找 PEP8 格式之外的东西。
我尝试了第一个示例,PyLint 0.18.1 给了我警告:
W: 1:spam: Dangerous default value [] as argument
如果这是您想要做的,那不是您的代码中的错误。但是,正如接受的答案中所指定的那样,空列表是一个“危险”的默认值,因为它很容易引入难以发现的问题。