Question

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?

Was it helpful?

Solution

Try using the new-style super calls:

class Foo(ctypes.BigEndianStructure):
    def __init__(self):
        super(Foo, self).__init__()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top