如果我从 ctypes.BigEndianStructure 派生一个类,如果我不调用 BigEndianStructure .__ init __(),pylint会发出警告。很好,但是如果我修复了我的代码,pylint仍会警告:

import ctypes

class Foo(ctypes.BigEndianStructure):
    def __init__(self):
        ctypes.BigEndianStructure.__init__(self)

$ pylint mymodule.py
C:  1: Missing docstring
C:  3:Foo: Missing docstring
W:  4:Foo.__init__: __init__ method from base class 'Structure' is not called
W:  4:Foo.__init__: __init__ method from base class 'BigEndianStructure' is not called
R:  3:Foo: Too few public methods (0/2)

起初我认为这是因为Structure来自C模块。如果我从我的一个类中继承,或者说 SocketServer.BaseServer 是纯python,我不会收到警告。但是,如果我从C代码中的 smbus.SMBus 继承,我也不会收到警告。

除了禁用W0231之外,任何人都知道解决方法吗?

有帮助吗?

解决方案

尝试使用新式 super 调用:

class Foo(ctypes.BigEndianStructure):
    def __init__(self):
        super(Foo, self).__init__()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top