我很想整合pylint进入构建过程
我的 python 项目,但我遇到了一个阻碍:其中一个
我发现非常有用的错误类型--:E1101: *%s %r has no %r
member*
--使用常见的django字段时经常报错,
例如:
E1101:125:get_user_tags: Class 'Tag' has no 'objects' member
这是由这段代码引起的:
def get_user_tags(username):
"""
Gets all the tags that username has used.
Returns a query set.
"""
return Tag.objects.filter( ## This line triggers the error.
tagownership__users__username__exact=username).distinct()
# Here is the Tag class, models.Model is provided by Django:
class Tag(models.Model):
"""
Model for user-defined strings that help categorize Events on
on a per-user basis.
"""
name = models.CharField(max_length=500, null=False, unique=True)
def __unicode__(self):
return self.name
如何调整 Pylint 以正确考虑对象等字段? (我还查看了 Django 源代码,但我一直无法找到 objects
的实现,所以我怀疑它不“只是”一个类字段。另一方面,我我对 python 还很陌生,所以我很可能忽略了一些东西。)
编辑: 我发现告诉 pylint 不对这些警告发出警告的唯一方法是阻止 (E1101) 类型的所有错误,这是 Not Acceptable 解决方案,因为那是 (在我看来)一个非常有用的错误。如果有另一种方法,而不增加 pylint 源,请指出具体细节:)
见 here总结一下我在使用 pychecker
和 pyflakes
时遇到的问题——事实证明,它们对于一般用途来说远非不稳定。 (在 pychecker 的情况下,崩溃源于 pychecker 代码——而不是它正在加载/调用的源代码。)
最佳答案
不要通过添加 ignores
或 generated-members
来禁用或削弱 Pylint 功能。
使用积极开发的 理解 Django 的 Pylint 插件。
This Pylint plugin for Django效果很好:
pip install pylint-django
并且在运行 pylint 时将以下标志添加到命令中:
--load-plugins pylint_django
详细博文here .
关于python - 在 Django 中使用 Pylint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/115977/