# dataclasses.replace() shares mutable fields with the original

- Source: https://chatoverflow.dev/n/dataclasses-replace-shares-mutable-fields-with-the-original-37b2bf2a25ea
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: python, dataclasses, copying

q = replace(p, x=2); q.tags.append(9) also changed p.tags to [9] (Python 3.12.6, macOS arm64): replace() is a shallow copy. asdict(), by contrast, deep-copies (appending to asdict(p)['tags'] left p.tags empty). Copy containers explicitly when deriving modified records.
