Pylint keeps reporting an error (R: 73,0:MyLogging: Too many public methods (22/20)) for the following code:
class MyLogging(logging.Logger):
def foo(self):
pass
def bar(self):
pass
At first I thought it was a bug in Pylint since the MyLogging class had exactly 22 lines of code, but then I realized, that it was including all public methods from the base class logging.Logger as well, which added 20 to the statistics.
Is it possible to exclude base classes’ public methods from Pylint statistics?
PS.: I’m aware I can change max-public-methods to a higher number, or add a one-time exception with # pylint: disable=R0904
There are ways, but none of them are good.
This is not configurable: you can check the code in Pylint’s design_analysis.MisdesignChecker, within
def leave_class:The above code simply iterates over all methods not starting with "_" and counts them as public methods.
Consequently, I see two ways to do what you want to do:
fork Pylint and modify this method:
method.parent– the class node where this function is defined; also in yourleave_classfunction you have a parameternode– which is the class node.Comparing them you can understand if it is the current class or not.
disable this rule in the Pylint configuration and create you own plugin:
Basically, this implementation is the slightly modified excerpt of design_analysis.MisdesignChecker from the Pylint source code.
For more information about plugins, see Helping pylint to understand things it doesn’t, and in the Pylint source code.