Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

too-few-public-methods: warn only for the parent class #4352

Open
praiskup opened this issue Apr 14, 2021 · 4 comments
Open

too-few-public-methods: warn only for the parent class #4352

praiskup opened this issue Apr 14, 2021 · 4 comments
Labels
Enhancement ✨ Improvement to a component

Comments

@praiskup
Copy link

Steps to reproduce

Given a file test.py:

#! /usr/bin/python3

# pylint: disable=missing-module-docstring

class Hello: # pylint: disable=too-few-public-methods
    """
    Some local class, but reproduced with external wtforms.FlaskForm, too.
    """

class World(Hello):
    """
    reported here:
    too-few-public-methods: Too few public methods (0/2)
    """
    def __init__(self):
        self.test = 0

Current behavior

Result of pylint /tmp/test.py:

************* Module test
/tmp/test.py:10:0: R0903: Too few public methods (0/1) (too-few-public-methods)

------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 7.69/10, -0.19)

Expected behavior

No error. When we inherit from some library class, no matter how many public
methods it provides, it should be acceptable to not add any more public
methods. One can e.g. only override some private method, some static class
attribute, rewrite __init__, ...

It isn't convenient to disable this warning for each class, and it is a pitty to
disable this for the whole project.

pylint --version output

Result of pylint --version output:

pylint 2.6.0
astroid 2.4.2
Python 3.9.4 (default, Apr  6 2021, 00:00:00)
[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]
@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Apr 14, 2021
@Pierre-Sassoulas
Copy link
Member

This make sense, thank you for opening the issue. We're also thinking about disabling this one by default in #3512

fedora-copr-github-bot pushed a commit to fedora-copr/copr that referenced this issue Apr 22, 2021
Reasons summarized in pylinrc file, and reported
pylint-dev/pylint#4352
@Avasam
Copy link

Avasam commented Feb 12, 2022

Upping this one, I like the rule but it happens so often with Flask

@alpaziz
Copy link

alpaziz commented May 26, 2022

Hello,
Hope everyone is well. Would there happen to be any updates on resolving this issue?

The too-few-public-methods is an important check, so we would like to include it in our project, however on top of praiskup’s point the check does not seem smart enough to detect the Parent Class‘s inherited public methods in the Child Class, when the Parent Class is being imported.

E.g.

#hello.py
class Hello:
    def hello(self):
        print('Hi')

    def goodbye(self):
         print(‘Bye’)

#world.py

from hello import Hello

class World(Hello):
    def __greeting(self):
        print('How are you?')

The above still throws the too-few-public-methods issue for Child Class World

@Pierre-Sassoulas
Copy link
Member

Hello, no one worked on it yet, but we welcome all contributions and will review proposals in (hopefully) a timely manner :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

No branches or pull requests

4 participants