continue
if f.name not in changes:
+ if f._field_type is _FIELD_INITVAR:
+ raise ValueError(f"InitVar {f.name!r} "
+ 'must be specified with replace()')
changes[f.name] = getattr(obj, f.name)
# Create the new object, which calls __init__() and
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: