使用Pylint与Django [英] Using Pylint with Django

查看:210
本文介绍了使用Pylint与Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常希望将 pylint 整合到
的构建过程中,我的python项目但是我遇到了一个show-stops:我觉得非常有用的
错误类型之一 - : E1101:*%s%r没有%r
成员*
- 在使用常用django字段时不断报告错误,例如

  E1101:125:get_user_tags:Class'Tag'没有'对象'成员

代码:

  def get_user_tags(username):

获取用户名所有的标签

返回一个查询集

return Tag.objects.filter(##这行触发错误
tagownership__users__username__exact = username)。 distinct()

#这是Tag类,models.Model由Django提供:
class Tag(models.Model):

模型用于用户定义的字符串t帽子可以在每个用户的基础上分类
上的事件。

name = models.CharField(max_length = 500,null = False,unique = True)

def __unicode __(self):
return self。名称

如何调整Pylint以适当地占用诸如对象等领域?(我也有查看Django源码,我一直找不到对象的实现,所以我怀疑它不是只是一个类字段,另一方面,我对于python来说,这是相当新鲜的,所以我可能会忽视某些东西。)



编辑:我发现告诉你的唯一方法pylint不警告这些警告是通过阻止所有类型的错误(E1101),这是不可接受的解决方案,因为(在我看来)是一个非常有用的错误,如果有另一种方式,没有增加pylint源,请指出具体细节:)



请参阅这里的总结我曾经遇到过与 pychecker pyflakes 的问题 - 他们已经被证明是非常不稳定的一般使用(在pychecker的情况下,崩溃起源于pychecker代码 - 不是源加载/调用。)

解决方案

我使用以下: pylint --generated-members = objects


I would very much like to integrate pylint into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:E1101: *%s %r has no %r member*--constantly reports errors when using common django fields, for example:

E1101:125:get_user_tags: Class 'Tag' has no 'objects' member

which is caused by this code:

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

How can I tune Pylint to properly take fields such as objects into account? (I've also looked into the Django source, and I have been unable to find the implementation of objects, so I suspect it is not "just" a class field. On the other hand, I'm fairly new to python, so I may very well have overlooked something.)

Edit: The only way I've found to tell pylint to not warn about these warnings is by blocking all errors of the type (E1101) which is not an acceptable solution, since that is (in my opinion) an extremely useful error. If there is another way, without augmenting the pylint source, please point me to specifics :)

See here for a summary of the problems I've had with pychecker and pyflakes -- they've proven to be far to unstable for general use. (In pychecker's case, the crashes originated in the pychecker code -- not source it was loading/invoking.)

解决方案

I use the following: pylint --generated-members=objects

这篇关于使用Pylint与Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆