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

Created on 10 Jul 2020  路  6Comments  路  Source: PyCQA/pylint

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_

contributor friendly enhancement help wanted

All 6 comments

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

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 comment now quoted, code example added

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"

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.

Configurable suppressions for classes would be generally useful:

Simple config override in .pylintrc for classes that:

# [CLASSRULES.]
# metaclass_match=
# parent_match=
# disable=list,of,disables

Would solve a lot of these issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GergelyKalmar picture GergelyKalmar  路  3Comments

pylint-bot picture pylint-bot  路  3Comments

lancelote picture lancelote  路  3Comments

glmdgrielson picture glmdgrielson  路  3Comments

mrginglymus picture mrginglymus  路  3Comments