Skip to content

Commit 1f3c6fe

Browse files
Add regression test for dataclass kw_only support (#7413)
Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 63dbc60 commit 1f3c6fe

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Pylint now understands the ``kw_only`` keyword argument for ``dataclass``.
2+
3+
Closes #7290, closes #6550, closes #5857
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Test the behaviour of the kw_only keyword."""
2+
3+
# pylint: disable=invalid-name
4+
5+
from dataclasses import dataclass
6+
7+
8+
@dataclass(kw_only=True)
9+
class FooBar:
10+
"""Simple dataclass with a kw_only parameter."""
11+
12+
a: int
13+
b: str
14+
15+
16+
@dataclass(kw_only=False)
17+
class BarFoo(FooBar):
18+
"""Simple dataclass with a negated kw_only parameter."""
19+
20+
c: int
21+
22+
23+
BarFoo(1, a=2, b="")
24+
BarFoo( # [missing-kwoa,missing-kwoa,redundant-keyword-arg,too-many-function-args]
25+
1, 2, c=2
26+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.10
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
missing-kwoa:24:0:26:1::Missing mandatory keyword argument 'a' in constructor call:UNDEFINED
2+
missing-kwoa:24:0:26:1::Missing mandatory keyword argument 'b' in constructor call:UNDEFINED
3+
redundant-keyword-arg:24:0:26:1::Argument 'c' passed by position and keyword in constructor call:UNDEFINED
4+
too-many-function-args:24:0:26:1::Too many positional arguments for constructor call:UNDEFINED

0 commit comments

Comments
 (0)