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

(no-value-for-parameter) on dataclass field attribute C0114 #5225

Closed
tweigel-dev opened this issue Oct 28, 2021 · 5 comments · Fixed by pylint-dev/astroid#1897
Closed

(no-value-for-parameter) on dataclass field attribute C0114 #5225

tweigel-dev opened this issue Oct 28, 2021 · 5 comments · Fixed by pylint-dev/astroid#1897
Assignees
Labels
Bug 🪲 dataclasses False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable

Comments

@tweigel-dev
Copy link

tweigel-dev commented Oct 28, 2021

Bug description

hay,
at working with dataclasses and pylint I noticed that pylint outputs a missleading error for generated attributes of dataclass.

from dataclasses import dataclass, field


@dataclass
class Person:
    """
    Class implementation to forecast on PRB
    """
    # pylint: disable=missing-function-docstring, too-many-instance-attributes, function-redefined,
    name: str
    last_char: int = field(init=True)

    @property
    def last_char(self):
        return self.name[-1]

    @last_char.setter
    def last_char(self, _):
        pass  # Do nothing, this is a read-only attribute

print(Person("Manfred"))

I got E1120: No value for argument 'last_char' in constructor call (no-value-for-parameter)

Command used

pylint ./bug-dataclasses.py

Pylint output

E1120: No value for argument 'last_char' in constructor call (no-value-for-parameter)

Expected behavior

No lint error

Pylint version

pylint 2.11.1
astroid 2.8.4
Python 3.9.5 (default, May 19 2021, 11:32:47) 
[GCC 9.3.0]
@tweigel-dev tweigel-dev added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 28, 2021
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 28, 2021
@pgoy-dod
Copy link

pgoy-dod commented Feb 3, 2022

Just adding my voice to this ticket to note that this also occurs in subclasses of dataclasses with default values. For example:

from dataclasses import dataclass


@dataclass
class Parent:
    name: str
    num_children: int = 1


@dataclass
class Grandparent(Parent):
    num_grandchildren: int = 1


 # complains with the "no-value-for-parameter" error for num_children, num_grandchildren
grandpa = Grandparent(name="Grampy") 

@plcarman
Copy link

plcarman commented Apr 4, 2022

Hitting this as well. The workaround I have for now is to set disable/enable blocks around the problematic code.

    #pylint: disable=no-value-for-parameter
    grandpa = Grandparent(name="Grampy") 
    #pylint: enable=no-value-for-parameter

@Pierre-Sassoulas
Copy link
Member

Another example from #7059 mentionned by @suryaavala:

# pylint: disable=missing-module-docstring, missing-class-docstring
from dataclasses import dataclass, field


@dataclass
class Mamal:
    name: str
    age: int
    mamal_subgroup: str


@dataclass
class Person(Mamal):
    name: str
    age: int
    mamal_subgroup: str = field(default="primates", init=False)


Person("John", 20)

@DanielNoord
Copy link
Collaborator

Related to #7291

@DanielNoord DanielNoord self-assigned this Dec 6, 2022
@DanielNoord
Copy link
Collaborator

I have decided to scope this to dataclasses and properties. This was indeed a false positive which I have now provided a fix for in astroid.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 dataclasses False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants