bpo-33796: Ignore ClassVar for dataclasses.replace(). (GH-7488)

This commit is contained in:
Eric V. Smith 2018-06-07 14:43:59 -04:00 committed by GitHub
parent 34b734699b
commit e7adf2ba41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 125 additions and 86 deletions

View file

@ -416,7 +416,7 @@ def _field_init(f, frozen, globals, self_name):
# Only test this now, so that we can create variables for the
# default. However, return None to signify that we're not going
# to actually do the assignment statement for InitVars.
if f._field_type == _FIELD_INITVAR:
if f._field_type is _FIELD_INITVAR:
return None
# Now, actually generate the field assignment.
@ -1160,6 +1160,10 @@ def replace(obj, **changes):
# If a field is not in 'changes', read its value from the provided obj.
for f in getattr(obj, _FIELDS).values():
# Only consider normal fields or InitVars.
if f._field_type is _FIELD_CLASSVAR:
continue
if not f.init:
# Error if this field is specified in changes.
if f.name in changes: