Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second order inheritance of dataclasses with default values/init=False causes E1120 no-value-for-parameter #10056

Open
SebastianGrans opened this issue Oct 30, 2024 · 0 comments
Labels
dataclasses False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@SebastianGrans
Copy link

SebastianGrans commented Oct 30, 2024

Bug description

If you have two layers of inheritance of dataclasses where the middle class has fields marked as field(default=<somevalue>, init=False), then instantiation of any child classes get marked as E1120 no-value-for-parameter, with a reference to those fields.

Similar issues with dataclasses and default values/init=False has been reported before: #7059 #5225

Example that cause E1120:

This yields an error only on the Child() call

@dataclass
class Base:
    id: int
    subid: int


@dataclass
class Derived(Base):
    id: int = field(default=0, init=False)


@dataclass
class Child(Derived):
    subid: int = field(default=1, init=False)


d = Derived(subid=1)
d = Child()

Chaging the id field in Derived to id: int = field(default=0) causes instantiation of both Derived and Child to be marked as E1120


Examples that does not yield E1120

A Child class that inherits from Parent where Parent has a default and init=False field

@dataclass
class Base:
    id: int = field(default=0, init=False)
    subid: int


@dataclass
class Child(Base):
    pass


c = Child(subid=1)

Command used

pylint --disable=C0114,C0115 testing.py

Disabling C0114 and C0115 (docstring warnings)

Pylint output

testing.py:24:4: E1120: No value for argument 'name' in constructor call (no-value-for-parameter)
testing.py:24:4: E1120: No value for argument 'id' in constructor call (no-value-for-parameter)

Expected behavior

This should not give E1120

Pylint version

pylint 3.3.1
astroid 3.3.5
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]

OS / Environment

Windows 11
Also tested in Ubuntu in WSL

@SebastianGrans SebastianGrans added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 30, 2024
@DanielNoord DanielNoord added False Positive 🦟 A message is emitted but nothing is wrong with the code dataclasses and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dataclasses False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

No branches or pull requests

2 participants