R0904 too-many-public-methods¶
- Message
'Too many public methods (%s/%s)'
- Description
Used when class has too many public methods, try to reduce this to get a simpler (and so easier to use) class.
Example¶
For the example, pylint was configured to accept at max five public methods on a class (default is 20).
class TooManyPublicMethods:
def meth1(self): pass
def meth2(self): pass
def meth3(self): pass
def meth4(self): pass
def meth5(self): pass
1:0: R0904: Too many public methods (5/4)
Why bother?¶
In most advice on code quality in object-oriented programs, there is some principle around classes having only limited responsibilities. E.g. in SOLID there is the Single-responsibility principle. When a class has a lot of public methods, it is likely in violation of that principle. You should consider if it can be split.
Running Pylint locally? In your CI?
There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.
Click here to find out more.