当前位置: 动力学知识库 > 问答 > 编程问答 >

python - pylint false positive for superclass __init__

问题描述:

If I derive a class from ctypes.BigEndianStructure, pylint warns if I don't call BigEndianStructure.init (). Great, but if I fix my code, pylint still warns:

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)

At first I thought this was because Structure comes from a C module. I don't get the warning if I subclass from one of my classes or, say, SocketServer.BaseServer which is pure python. But I also don't get the warning if I subclass from smbus.SMBus, which is in a C module.

Anyone know of a workaround other than disabling W0231?

网友答案:

Try using the new-style super calls:

class Foo(ctypes.BigEndianStructure):
    def __init__(self):
        super(Foo, self).__init__()
分享给朋友:
您可能感兴趣的文章:
随机阅读: