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クラスの1つ、または純粋な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 に答える