diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2018-06-23 14:46:32 (GMT) |
---|---|---|
committer | Eric V. Smith <ericvsmith@users.noreply.github.com> | 2018-06-23 14:46:32 (GMT) |
commit | 3d70f7aef614c396f516b5fccedeebe98598714d (patch) | |
tree | b811dc51f5c680418baa0629eb16fb5b6fca9b94 /Lib/test | |
parent | 66ecefcfe77348ce12d3a951e8e6cd3ad274b24a (diff) | |
download | cpython-3d70f7aef614c396f516b5fccedeebe98598714d.zip cpython-3d70f7aef614c396f516b5fccedeebe98598714d.tar.gz cpython-3d70f7aef614c396f516b5fccedeebe98598714d.tar.bz2 |
bpo-33805: Improve error message of dataclasses.replace() (GH-7580)
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/test_dataclasses.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index 9297931..d9556c7 100755 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -3024,6 +3024,22 @@ class TestReplace(unittest.TestCase): replace(c, x=5) + def test_initvar_is_specified(self): + @dataclass + class C: + x: int + y: InitVar[int] + + def __post_init__(self, y): + self.x *= y + + c = C(1, 10) + self.assertEqual(c.x, 10) + with self.assertRaisesRegex(ValueError, r"InitVar 'y' must be " + "specified with replace()"): + replace(c, x=3) + c = replace(c, x=3, y=5) + self.assertEqual(c.x, 15) ## def test_initvar(self): ## @dataclass ## class C: |