Skip to content

False positives with dataclasses #5857

Closed
@bretttully

Description

@bretttully

Bug description

"""repr=False causes false positives"""
import dataclasses


@dataclasses.dataclass(frozen=True)
class ExampleA:
    """Base class"""

    var_a: int


@dataclasses.dataclass(frozen=True, repr=False)
class ExampleB(ExampleA):
    """Child class with no repr"""

    var_b: int = 10


a = ExampleA(1)
assert a.var_a == 1

b = ExampleB(2)
assert b.var_a == 2
assert b.var_b == 10

b = ExampleB(2, 3)  # Too many positional arguments for constructor call
assert b.var_a == 2
assert b.var_b == 3

b = ExampleB(2, var_b=3)  # Unexpected keyword argument 'var_b' in constructor call
assert b.var_a == 2
assert b.var_b == 3

Configuration

No response

Command used

pylint tmp.py

Pylint output

************* Module tmp
tmp.py:26:4: E1121: Too many positional arguments for constructor call (too-many-function-args)
tmp.py:30:4: E1123: Unexpected keyword argument 'var_b' in constructor call (unexpected-keyword-arg)

------------------------------------------------------------------
Your code has been rated at 3.75/10 (previous run: 2.50/10, +1.25)

Expected behavior

No warnings produced

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.8.12 | packaged by conda-forge | (default, Jan 30 2022, 23:42:07) 
[GCC 9.4.0]

OS / Environment

Ubuntu 20.04, clean conda env

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions