bpo-33805: Improve error message of dataclasses.replace() (GH-7580)
(cherry picked from commit 3d70f7aef614c396f516b5fccedeebe98598714d)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 96bf6e1..ad7bf0f 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -1173,6 +1173,9 @@
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