pylint
pylint copied to clipboard
Do not raise ``too-many-instance-attributes`` on dataclasses or with a higher threshold
Current problem
Dataclasses sometimes deliberately have a lot of arguments, which is also the purpose of the classes. With normal classes, methods and functions it makes sense if the argument list is not too long.
Desired solution
Therefore a conscious distinction between dataclass and normal class would be meaningful with the argument number.
Additional context
No response
@vince6e74 Could you give an example of this?
I presume an example describing what the OP means could be:
# pylint: disable=missing-class-docstring,missing-module-docstring
from dataclasses import dataclass
@dataclass
class Foo:
one: int
two: int
three: int
four: int
five: int
six: int
seven: int
eight: int
Output:
$ > pylint test.py
************* Module test
test.py:7:0: R0902: Too many instance attributes (8/7) (too-many-instance-attributes)
------------------------------------------------------------------
Your code has been rated at 9.00/10 (previous run: 0.00/10, +9.00)
I've encountered the same situation myself. I would have expected that dataclasses are excluded from the R0902 check. AFAIK, I do not know of a way to specifically indicate dataclasses are to be treated differently in that situation.
…while with
class Foo(NamedTuple):
one: int
two: int
three: int
four: int
five: int
six: int
seven: int
eight: int
nine: int
ten: int
eleven: int
twelve: int
thirteen: int
fourteen: int
fifteen: int
pylint is totally happy and does not complain at all.