summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2018-06-07 18:43:59 (GMT)
committerGitHub <noreply@github.com>2018-06-07 18:43:59 (GMT)
commite7adf2ba41832404100313f9ac9d9f7fabedc1fd (patch)
treec074a386410628e15dc7ea0b9db06e2cd68b1fbc /Lib/dataclasses.py
parent34b734699b19d826f861b604dd77e82beed95f17 (diff)
downloadcpython-e7adf2ba41832404100313f9ac9d9f7fabedc1fd.zip
cpython-e7adf2ba41832404100313f9ac9d9f7fabedc1fd.tar.gz
cpython-e7adf2ba41832404100313f9ac9d9f7fabedc1fd.tar.bz2
bpo-33796: Ignore ClassVar for dataclasses.replace(). (GH-7488)
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 2c5593b..96bf6e1 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -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: