如何避免Pylint警告构造函数的继承类在Python 3? [英] How to avoid Pylint warnings for constructor of inherited class in Python 3?

查看:1046
本文介绍了如何避免Pylint警告构造函数的继承类在Python 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python 3中,我有以下代码:

  class A:
def __init __
pass

class B(A):
def __init __(self):
super().__ init __()

这会产生Pylint警告:



  • 定义旧样式类。 (旧式类)

  • 在旧样式类(超级旧类)上使用super


在我的理解中,在Python 3中不存在旧式的类了,这段代码是可以的。



即使我用这个代码明确使用新式的类

  class A(object):
def __init __(self):
pass

class B(A):
def __init __(self):
super().__ init __()



我得到Pylint警告,因为在Python 3中调用父构造函数的语法不同:



  • 缺少super()的参数(缺少超参数)

$ b $所以,我如何告诉Pylint我想检查Python 3代码,以避免这些消息(没有禁用Pylint检查)?

解决方案

这是由于astroid中的一个错误,这不是将所有类都视为新样式w / python 3之前 https://bitbucket.org/logilab/astroid/commits/6869fb2acb9f58f0ba2197c6e9008989d85ca1ca



这应该很快发布。


In Python 3, I have the following code:

class A:
    def __init__(self):
        pass

class B(A):
    def __init__(self):
        super().__init__()

This yields the Pylint warning:

  • Old-style class defined. (old-style-class)
  • Use of super on an old style class (super-on-old-class)

In my understanding, in Python 3 there does not exist an old-style class anymore and this code is OK.

Even if I explicitly use new-style classes with this code

class A(object):
    def __init__(self):
        pass

class B(A):
    def __init__(self):
        super().__init__()

I get Pylint warning because of the different syntax to call the parent constructor in Python 3:

  • Missing argument to super() (missing-super-argument)

So, how can I tell Pylint that I want to check Python 3 code to avoid these messages (without disabling the Pylint check)?

解决方案

This is due to a bug in astroid, which wasn't considering all classes as new style w/ python 3 before https://bitbucket.org/logilab/astroid/commits/6869fb2acb9f58f0ba2197c6e9008989d85ca1ca

That should be released shortly.

这篇关于如何避免Pylint警告构造函数的继承类在Python 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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