如何避免Python3中继承类的构造函数出现Pylint警告?

如何避免Python3中继承类的构造函数出现Pylint警告?,python,inheritance,python-3.x,constructor,pylint,Python,Inheritance,Python 3.x,Constructor,Pylint,在Python 3中,我有以下代码: class A: def __init__(self): pass class B(A): def __init__(self): super().__init__() 这将产生Pylint警告: 已定义旧样式类。(老式班) 在旧式类上使用super(在旧类上使用super) 据我所知,在Python3中不再存在旧式的类,这段代码也可以 即使我在代码中显式使用了新样式的类 class A(object)

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

class A:
    def __init__(self):
        pass

class B(A):
    def __init__(self):
        super().__init__()
这将产生Pylint警告:

  • 已定义旧样式类。(老式班)
  • 在旧式类上使用super(在旧类上使用super)
据我所知,在Python3中不再存在旧式的类,这段代码也可以

即使我在代码中显式使用了新样式的类

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

class B(A):
    def __init__(self):
        super().__init__()
我得到Pylint警告是因为在Python 3中调用父构造函数的语法不同:

  • super()缺少参数(缺少超级参数)
那么,我如何告诉Pylint我想检查Python 3代码以避免这些消息(而不禁用Pylint检查)?

根据“super()缺少参数”的代码E1004:。如果只想禁用一种类型的警告,可以在文件开头添加此行:

# pylint: disable=E1004
或者您可以尝试调用
super()
,如下所示:

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

这是因为astroid中有一个bug,它以前没有将所有类都看作是新样式的w/python 3


这将很快发布。

谢谢,您甚至可以通过
#pylint:disable=missing super-argument
禁用该消息。但是,我的Python代码是否有问题,或者Pylint与Python 3不兼容?我不确定,因为我运行的是Python 2.7。pylint版本1.1也应该支持python 3。谢谢!这就提出了另外一个问题:如何告诉Pylint,在检查时使用哪个Python版本。我为此输入了一个新问题: