Pylint 的“公共方法太少"是什么意思?留言是什么意思? [英] What does Pylint's "Too few public methods" message mean?

查看:59
本文介绍了Pylint 的“公共方法太少"是什么意思?留言是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些代码上运行 Pylint,并收到错误公共方法太少 (0/2)".这条消息是什么意思?

I'm running Pylint on some code, and receiving the error "Too few public methods (0/2)". What does this message mean?

Pylint 文档没有帮助:

当一个类的公共方法太少时使用,所以要确保它真的值得.

Used when a class has too few public methods, so be sure it's really worth it.

推荐答案

这个错误基本上是说类并不只是存储数据,因为你基本上把类当作字典.类应该至少有几个方法来操作它们所持有的数据.

The error basically says that classes aren't meant to just store data, as you're basically treating the class as a dictionary. Classes should have at least a few methods to operate on the data that they hold.

如果您的课程如下所示:

If your class looks like this:

class MyClass(object):
    def __init__(self, foo, bar):
        self.foo = foo
        self.bar = bar

考虑使用字典或 namedtuple 代替.尽管如果一个类看起来是最好的选择,请使用它.Pylint 并不总是知道什么是最好的.

Consider using a dictionary or a namedtuple instead. Although if a class seems like the best choice, use it. Pylint doesn't always know what's best.

请注意,namedtuple 是不可变的,实例化时分配的值以后不能修改.

Do note that namedtuple is immutable and the values assigned on instantiation cannot be modified later.

这篇关于Pylint 的“公共方法太少"是什么意思?留言是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆