bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867)
Co-Authored-By: Claudiu Popa <pcmanticore@gmail.com>
Automerge-Triggered-By: GH:ericvsmith
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 422a95c..3de2ec0 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -1300,7 +1300,7 @@ class C:
continue
if f.name not in changes:
- if f._field_type is _FIELD_INITVAR:
+ if f._field_type is _FIELD_INITVAR and f.default is MISSING:
raise ValueError(f"InitVar {f.name!r} "
'must be specified with replace()')
changes[f.name] = getattr(obj, f.name)