aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_dataclasses.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r--Lib/test/test_dataclasses.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index 0bfed41b369..4f5c3c8aab1 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -3251,6 +3251,24 @@ class TestReplace(unittest.TestCase):
c = replace(c, x=3, y=5)
self.assertEqual(c.x, 15)
+ def test_initvar_with_default_value(self):
+ @dataclass
+ class C:
+ x: int
+ y: InitVar[int] = None
+ z: InitVar[int] = 42
+
+ def __post_init__(self, y, z):
+ if y is not None:
+ self.x += y
+ if z is not None:
+ self.x += z
+
+ c = C(x=1, y=10, z=1)
+ self.assertEqual(replace(c), C(x=12))
+ self.assertEqual(replace(c, y=4), C(x=12, y=4, z=42))
+ self.assertEqual(replace(c, y=4, z=1), C(x=12, y=4, z=1))
+
def test_recursive_repr(self):
@dataclass
class C: