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 unexpected-keyword-arg regression for dataclasses #7434

Closed
mattclay opened this issue Sep 7, 2022 · 3 comments · Fixed by pylint-dev/astroid#1812
Closed
Assignees
Labels
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

@mattclay
Copy link

mattclay commented Sep 7, 2022

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

@mattclay mattclay added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas added 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 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 7, 2022
@DanielNoord DanielNoord self-assigned this Sep 8, 2022
@DanielNoord
Copy link
Collaborator

@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.

@Pierre-Sassoulas
Copy link
Member

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 ?

@DanielNoord
Copy link
Collaborator

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.

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 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.

4 participants