我在(很多)我的Python文件中有这个代码用于项目。
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pprint import pformat
Pylint抱怨说:
==ook:2
==eek:2
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pprint import pformat (duplicate-code)
虽然这是完全无关紧要的。来自to prevent compatibility regressions的from __future__ [...]
行Python 2 to Python 3。因此,pylint不应该抱怨它们在不同的文件中是相似的。
有没有办法阻止pytlint这样做?
我知道pylint: disable=duplicate-code
,但由于导入范围,这将禁用整个文件。但是,我不想为整个文件禁用它。
答案 0 :(得分:-2)
在这种情况下,为什么不一行导入软件包?
class ArticlePkAndSlug(models.Model):
STATUS_CHOICES = (('Offer', 'Offer'),('Archive', 'Archive'),)
title = models.CharField(max_length=settings.BLOG_TITLE_MAX_LENGTH)
status = models.CharField(max_length=settings.BLOG_TITLE_MAX_LENGTH,null = True,blank=True,choices=STATUS_CHOICES)
#description = models.CharField(max_length=1000)
slug0 = models.SlugField(
default="", editable=False, max_length=settings.BLOG_TITLE_MAX_LENGTH
)
slug1 = models.SlugField(
default="", editable=False, max_length=settings.BLOG_TITLE_MAX_LENGTH
)
def get_absolute_url(self):
#kwargs = { "pk": self.id, "slug": self.slug}
kwargs = {"slug0": self.slug0, "pk": self.id, "slug1": self.slug1}
return reverse("article-pk-slug-detail", kwargs=kwargs)
def save(self, *args, **kwargs):
status = self.status
title = self.title.replace(" ", "_")
self.slug0 = slugify(status,allow_unicode=True)
self.slug1 = slugify(title,allow_unicode=True)
super().save(*args, **kwargs)
Pylint寻找最少的重复行数(默认为4),因此可以解决此问题。