pylint icon indicating copy to clipboard operation
pylint copied to clipboard

do not report too-few-public-methods for `attr.s`, `attr.dataclass`, `typing.NamedTuple` and similar.

Open graingert opened this issue 3 years ago • 12 comments

do not report too-few-public-methods for attr.s, attr.dataclass, typing.NamedTuple and similar.

example:

import attr

@attr.dataclass(frozen=True)  # pylint-ignore: too-few-public-methods
class Foo:
    ham: str
    spam: str

@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.

Originally posted by @PCManticore in https://github.com/PyCQA/pylint/issues/2710#issuecomment-458157179

graingert avatar Jul 10 '20 11:07 graingert

I'm not sure why this reopened, I am no longer using pylint (moved to flake8) so no interest in this anymore. Thanks

uriva avatar Jul 10 '20 11:07 uriva

I am also not sure why you copied the comment outright pinging all involved rather than posting only relevant part.

Posting "I'm going to close this issue" while opening an issue is bizarre.

Also: give a code sample wrongly reported as mistake.

matkoniecz avatar Jul 10 '20 11:07 matkoniecz

@matkoniecz comment now quoted, code example added

graingert avatar Jul 10 '20 11:07 graingert

I am also not sure why you copied the comment outright pinging all involved rather than posting only relevant part.

I just hit the "reference in new issue button"

graingert avatar Jul 10 '20 16:07 graingert

This message is probably going to be disabled by default because there is a lot of example of place where it makes sense to have few public method (Django Meta class, inheritance of class that implements a run() function etc.) See #3512 . If you think this is useful and want to use it, but with a whitelist of class that can have few public method, I don't think there is an easy way to do that right now, but I think this is doable.

Pierre-Sassoulas avatar Aug 09 '20 20:08 Pierre-Sassoulas

Configurable suppressions for classes would be generally useful:

Simple config override in .pylintrc for classes that:

# [CLASSRULES.<CUSTOM_NAME>] # metaclass_match=<metaclass_regex> # parent_match=<parent_regex> # disable=list,of,disables

Would solve a lot of these issues.

earonesty avatar Dec 26 '20 16:12 earonesty

Also true for exceptions see : #4464

Pierre-Sassoulas avatar May 11 '21 23:05 Pierre-Sassoulas

Also true for anything inheriting from typing.Protocol.

wnoise avatar May 15 '21 04:05 wnoise

@Pierre-Sassoulas why was this unpinned?

graingert avatar Jul 23 '21 09:07 graingert

this should also not report: too-many-instance-attributes for attr.s

graingert avatar Jul 23 '21 09:07 graingert

I unpinned it because there was more pressing issues to advertise first (ranked according to number of thumbsup or heart reactions), it does not mean that I would not review a fix for this ;)

Pierre-Sassoulas avatar Jul 23 '21 16:07 Pierre-Sassoulas

What about context managers? May pylint detect them by __enter__() and __exit__() methods defined?

g1itch avatar Jul 29 '21 10:07 g1itch