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/