Can inherited public methods be excluded from Pylint's statistics?

Solution 1:

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:

for method in node.methods():
    if not method.name.startswith('_'):
        nb_public_methods += 1

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:

  1. fork Pylint and modify this method:

     for method in node.methods():
         if not method.name.startswith('_') and method.parent == node:
             nb_public_methods += 1
    

    method.parent - the class node where this function is defined; also in your leave_class function you have a parameter node - which is the class node.

    Comparing them you can understand if it is the current class or not.

  2. disable this rule in the Pylint configuration and create you own plugin:

     MAX_NUMBER_PUBLIC_METHODS = 3
     class PublicMethodsChecker(BaseChecker):
         __implements__ = (IASTNGChecker,)
    
         name = 'custom-public-methods-checker'
    
         msgs = {
             "C1002": ('Too many public methods (%s/%s)',
                   'Used when class has too many public methods, try to reduce \
                    this to get a more simple (and so easier to use) class.'),
         }
    
         def leave_class(self, node):
             """check number of public methods"""
             nb_public_methods = 0
             print type(node)
             for method in node.methods():
                 if not method.name.startswith('_') and method.parent == node:
                     nb_public_methods += 1
             if nb_public_methods > MAX_NUMBER_PUBLIC_METHODS:
                  self.add_message('C1002',
                              node=node,
                              args=(nb_public_methods, MAX_NUMBER_PUBLIC_METHODS))
    

    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.

Solution 2:

There is currently no configuration in pylint allowing to ignore parent methods. You may do what Romanl is suggesting to by pass the problem until the issue I've created for your pb is resolved upstream (http://www.logilab.org/ticket/116963)