pylint 超类 __init__ 误报
如果我从 ctypes.BigEndianStructure
派生一个类,如果我不调用 BigEndianStructure.__init__()
,pylint 会发出警告。 很好,但是如果我修复我的代码,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 模块。 如果我从我的一个类中继承子类,或者例如纯 python 的 SocketServer.BaseServer ,我不会收到警告。 但如果我从 C 模块中的 smbus.SMBus
子类化,我也不会收到警告。
除了禁用 W0231 之外,有人知道解决方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用新式
super
调用:Try using the new-style
super
calls: