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

Is too-few-public-methods (R0903) really useful? #2710

Closed
uriva opened this issue Jan 28, 2019 · 7 comments
Closed

Is too-few-public-methods (R0903) really useful? #2710

uriva opened this issue Jan 28, 2019 · 7 comments

Comments

@uriva
Copy link

uriva commented Jan 28, 2019

This message over triggers many times, e.g. for dataclasses (or at least the backport to python 3.6).

See other examples in https://stackoverflow.com/questions/14027417/what-does-pylints-too-few-public-methods-message-mean

Consider removing altogether.

@matkoniecz
Copy link

Can you provide examples here? External sites may be changed so link only reports are not too useful.

@matkoniecz
Copy link

matkoniecz commented Jan 28, 2019

And the first example that I spotted, in https://stackoverflow.com/a/14027686/4130619 is a case where complaint makes a perfect sense.

@PCManticore
Copy link
Contributor

@uriva As mentioned by @matkoniecz in most cases the check makes sense. If your class has a single method on it, it's probably a function in disguise. You can also configure the number of public methods with min-public-methods. But there are a couple of classes for which we should not report this, as it makes perfect sense to not have too many methods or no methods at all. This includes attrs, dataclasses, typing.NamedTuple and similar.
Given that your issue is about the removal of the method, I'm going to close this issue, but if you have an example where pylint complains about a dataclass, please open a separate issue.

@uriva uriva changed the title Is too-few-public-methods (R0903 ) really useful? Is too-few-public-methods (R0903) really useful? Jan 29, 2019
@uriva
Copy link
Author

uriva commented Jan 29, 2019

Ok.
It might be a good idea to analyze which warnings people disable so this discussion becomes more objective.

@kuwv
Copy link

kuwv commented Feb 7, 2024

@matkoniecz @PCManticore there is one false positive where this really shouldn't trigger.

Descriptors (or class-based properties) contain only dunders (which are not technically private methods anyway since many can be called directly):

class Example:
    __get__(self, obj: object, owner: Optional[Type[object]] = None) -> T:
        ...
    __set__(self, obj: object, value: T) -> None:
        ...

I don't remember if single-method classes trigger, but a lot of common OOP design patterns use these (Additionally mixins can be lumped in this as well).

class Converter(AbstractImpl):
    def convert(self, content: Dict[str, Any]) -> str:
        ...

It's probably fine to trigger on though, but IMO a bit inaccurate in that Python is intended to be an OOP first language.

@matkoniecz
Copy link

it may be better to open new issue over commenting in 2019 one

@kuwv
Copy link

kuwv commented Feb 8, 2024

Ok, I'll create a new issue and reference this for @uriva.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants