python - Pylint的R0902是什么意思?为什么我们有这个限制?

标签 python pylint

R0902限值的背后是什么?太多的实例属性会减慢 python 解释器的速度,还是仅仅是因为太多的实例属性会使类更难理解?

最佳答案

来自(DOCS):

too-many-instance-attributes (R0902):

  • Too many instance attributes (%s/%s) Used when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class.

然后从 ( Tutorial ):

... but I have run into error messages that left me with no clue about what went wrong, simply because I was unfamiliar with the underlying mechanism of code theory. One error that puzzled my newbie mind was:

:too-many-instance-attributes (R0902): *Too many instance attributes (%s/%s)*

I get it now thanks to Pylint pointing it out to me. If you don’t get that one, pour a fresh cup of coffee and look into it - let your programmer mind grow!

所以,是的,这还不是很清楚。

但是,如上文所述,对于方法、类和模块,越小通常越有利于理解能力、可重用性以及可管理性。当事情变得太大时,通常表明可以重构事情以使其变小。确实没有办法对此设置硬性限制,正如 this question 中所讨论的那样关于如何关闭此消息,pylint 不应该是硬道理

因此,请将消息作为提示来进一步研究该部分代码。

关于python - Pylint的R0902是什么意思?为什么我们有这个限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42018179/

相关文章:

python - torch.rand(1, 3, 64, 64) 是什么意思?

python - 是否可以从模块导入变量以便与 Selenium 一起使用?

python - Pandas:用组的模式填充 na

python - 皮林特最佳实践

python - 如何安装 Pylint,克服错误

python - Twisted 和 PyBluez 一起工作?

python - 为循环优化 Django Queryset

python - 如何设置pylint分数阈值?

python - 避免在 gitlab CI 脚本管道中提前退出命令,同时仍捕获退出状态

python - pylint "invalid syntax"(语法错误)来自 '*='