tags:

views:

191

answers:

1

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?

+2  A: 

Try using the new-style super calls:

class Foo(ctypes.BigEndianStructure):
    def __init__(self):
        super(Foo, self).__init__()
jkp
Ahh, that should have been the obvious thing to try. Thanks. It fixes the warning. I'm curious though, do Structure/BigEndianStructure use super()? The advice I've seen is to use super() iff the superclass uses super()...
bstpierre