pylint
pylint copied to clipboard
False positive `unexpected-keyword-arg` regression for dataclasses
Bug description
A false positive is reported for unexpected-keyword-arg starting with pylint 2.15.0 for dataclasses with multiple inheritance, as seen in the code below. The issue is present in the latest version (2.15.2). The issue was not present in pylint 2.14.5.
# main.py
# pylint: disable=C
import dataclasses
@dataclasses.dataclass
class A:
required: bool
@dataclasses.dataclass
class B1(A):
pass
@dataclasses.dataclass
class B2(A):
optional: bool = False
@dataclasses.dataclass
class C(B1, B2):
pass
C(
required=True,
optional=True,
)
Configuration
No response
Command used
pylint main.py
Pylint output
************* Module main
main.py:27:0: E1123: Unexpected keyword argument 'optional' in constructor call (unexpected-keyword-arg)
Expected behavior
No issues should be reported.
Pylint version
pylint 2.15.2
astroid 2.12.9
Python 3.9.5 (default, Nov 23 2021, 15:27:38)
[GCC 9.3.0]
OS / Environment
Ubuntu 20.04.5
Additional dependencies
No response
@Pierre-Sassoulas I'm never touching the dataclass code ever again... Sorry about this, our tests really were not exhaustive it seems.
@mattclay I'll try and get a fix for this somewhere this week.
I'm never touching the dataclass code ever again... Sorry about this, our tests really were not exhaustive it seems.
Don't worry. Astroid brains for very popular classes are hardcore to change. If we could remove the brain altogether and understand the code directly with astroid it would avoid a lot of problem.. but I guess dataclasses are a C extension ?
but I guess dataclasses are a C extension ?
Not the main issue is that dataclasses are created through a wrapping decorator. We have trouble understanding the wrapper and then we are unable to understand all the side effects of this wrapping function such as changing the __init__. I don't think we'll ever do without the brain for dataclasses.