如何修复 pylint 警告“未引用抽象类”?
我有一个 Python 类,它为几个方法引发“NotImplementedError”,并且该类由在自己的文件中定义的其他一些类继承。
当我在具有抽象类的文件上运行 Pylint 时,它总是抱怨“未引用抽象类”。我想知道这只是 Pylint 的偏执还是我确实需要解决一些问题?
I have a Python class that raises "NotImplementedError" for a couple of methods and the class is inherited by a few other classes which are defined in their own files.
When I run Pylint on the file that has the abstract class, it always complains "Abstract class not referenced". I was wondering is it just Pylint being paranoid or there's actually something I do need to fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的类中有一个引发
NotImplementedError
的方法,则足以让 pylint 认为这是一个抽象类。当 pylint 检查与项目其余部分隔离的每个文件时,如果没有人从文件中的此类继承,则会引发此消息。
如果您想停用它,您必须将此注释放在类定义之前:
If you have in your class a method raising a
NotImplementedError
it is enough to make pylint think this is an abstract class.As pylint check each file isolated from the rest of the project, if no one inherit from this class in the file it will raise this message.
If you want to desactivate it you'll have to put this comment before your class definition :
Pylint 认为每个文件都是“独立的”,因此当检查定义抽象类但没有子类的文件时,它会抱怨 R0921 (http://www.logilab.org/card/pylintfeatures)。
事实上,消息类型是“R”,它代表“重构”(http://www.logilab.org/card/pylint_manual#pylint-output):Pylint 建议“良好实践”,但你可以愉快地离开就这样。
Pylint considers each file "self-contained", so when checking the file where you defined your abstract class, but no subclasses, it complains with R0921 (http://www.logilab.org/card/pylintfeatures).
In fact, the message type is "R", which stands for "refactor" (http://www.logilab.org/card/pylint_manual#pylint-output): Pylint is suggesting "good practice", but you can happily leave it like that.