2

如果我从 派生一个类ctypes.BigEndianStructure,如果我不调用,pylint 会发出警告BigEndianStructure.__init__()。很好,但是如果我修复我的代码,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 ,我不会收到警告。smbus.SMBus但是,如果我从C 模块中的子类化,我也不会收到警告。

有人知道除了禁用 W0231 之外的解决方法吗?

4

1 回答 1

6

尝试使用新式super调用:

class Foo(ctypes.BigEndianStructure):
    def __init__(self):
        super(Foo, self).__init__()
于 2009-07-29T15:44:55.737 回答