pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive for missing-kwoa (E1125) on inherited dataclasses with kw_only=True

Open taschini opened this issue 3 months ago • 2 comments

Bug description

This code is fine:

# minimal.py
from dataclasses import dataclass, field


@dataclass(kw_only=True)
class Base:
    x: int
    y: int


class SumMixin:

    def sum(self):
        return self.x + self.y


@dataclass(kw_only=True)
class Intermediate(Base, SumMixin):

    x: int = field(init=False)

    def __post_init__(self):
        self.x = 4


@dataclass(kw_only=True)
class Example(Intermediate):

    message: str

    def help(self):
        return self.message.format(self.sum())


if __name__ == "__main__":
    print(Example(y=3, message="Here it is: {}").sum())

Configuration

No response

Command used

pylint --disable=all --enable=missing-kwoa minimal.py

Pylint output

************* Module minimal
minimal.py:34:10: E1125: Missing mandatory keyword argument 'x' in constructor call (missing-kwoa)

Expected behavior

There should be no findings.

Pylint version

pylint 3.1.0
astroid 3.1.0
Python 3.11.6 (main, Nov 20 2023, 13:25:53) [GCC 11.4.0]

OS / Environment

No response

Additional dependencies

No response

taschini avatar Mar 23 '24 07:03 taschini

pylint --enable=missing-kwoa minimal.py try use this cmd

joel6948 avatar Apr 01 '24 06:04 joel6948

The false positive is still there, obviously.

taschini avatar Apr 02 '24 05:04 taschini