Skip to content

Add regression test for dataclass kw_only support #7413

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

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7290.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pylint now understands the ``kw_only`` keyword argument for ``dataclass``.

Closes #7290, closes #6550, closes #5857
26 changes: 26 additions & 0 deletions tests/functional/d/dataclass_kw_only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Test the behaviour of the kw_only keyword."""

# pylint: disable=invalid-name

from dataclasses import dataclass


@dataclass(kw_only=True)
class FooBar:
"""Simple dataclass with a kw_only parameter."""

a: int
b: str


@dataclass(kw_only=False)
class BarFoo(FooBar):
"""Simple dataclass with a negated kw_only parameter."""

c: int


BarFoo(1, a=2, b="")
BarFoo( # [missing-kwoa,missing-kwoa,redundant-keyword-arg,too-many-function-args]
1, 2, c=2
)
2 changes: 2 additions & 0 deletions tests/functional/d/dataclass_kw_only.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.10
4 changes: 4 additions & 0 deletions tests/functional/d/dataclass_kw_only.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
missing-kwoa:24:0:26:1::Missing mandatory keyword argument 'a' in constructor call:UNDEFINED
missing-kwoa:24:0:26:1::Missing mandatory keyword argument 'b' in constructor call:UNDEFINED
redundant-keyword-arg:24:0:26:1::Argument 'c' passed by position and keyword in constructor call:UNDEFINED
too-many-function-args:24:0:26:1::Too many positional arguments for constructor call:UNDEFINED