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

False positive with dataclass multiple inheritance and field init #7427

Closed
tomsilver opened this issue Sep 7, 2022 · 1 comment · Fixed by pylint-dev/astroid#1774
Closed

Comments

@tomsilver
Copy link

Bug description

pylint emits a false positive too-many-function-args in the following situation:

from dataclasses import dataclass, field

@dataclass
class A:
    _foo: bool = field(init=False)

    def __post_init__(self) -> None:
        self._foo = True


@dataclass
class B:
    bar: bool


@dataclass
class C(A, B):
    pass


a = A()
assert a._foo  # no error

b = B(False)
assert not b.bar  # no error

c = C(False)  # too-many-function-args
assert not c.bar
assert c._foo

Note: This is new in pylint==2.15.0. There is no false positive with pylint==2.14.5.

Configuration

No response

Command used

pylint --disable all --enable too-many-function-args example.py

Pylint output

************* Module bug
bug.py:27:4: E1121: Too many positional arguments for constructor call (too-many-function-args)

------------------------------------------------------------------
Your code has been rated at 6.88/10 (previous run: 6.88/10, +0.00)

Expected behavior

pylint should not raise too-many-function-args

Pylint version

pylint 2.15.0
astroid 2.12.8
Python 3.9.4 (default, Aug  1 2022, 10:10:32)

OS / Environment

macOS Monterey 12.5.1

Additional dependencies

No response

@tomsilver tomsilver added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 7, 2022
@DanielNoord DanielNoord added Regression dataclasses and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 7, 2022
@DanielNoord
Copy link
Collaborator

Thanks for the report! A fix should be available somewhere today/tonight when we release a new version of pylint and astroid 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants