diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-06-07 20:15:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-07 20:15:23 (GMT) |
commit | 0aee3bea197af51de3a30e4665eaa2971a681fbb (patch) | |
tree | ef91711722b19d5708af0dda0d84e3af29b8fa01 /Lib/dataclasses.py | |
parent | e4b2bdfdcff7ba6a8676494a295434a4a6f5917a (diff) | |
download | cpython-0aee3bea197af51de3a30e4665eaa2971a681fbb.zip cpython-0aee3bea197af51de3a30e4665eaa2971a681fbb.tar.gz cpython-0aee3bea197af51de3a30e4665eaa2971a681fbb.tar.bz2 |
bpo-33796: Ignore ClassVar for dataclasses.replace(). (GH-7488)
(cherry picked from commit e7adf2ba41832404100313f9ac9d9f7fabedc1fd)
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r-- | Lib/dataclasses.py | 6 |
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: |