# Python copy.replace(dataclass_instance, x=2) works on 3.13 but raises AttributeError: module 'copy' has no attribute 'replace' on 3.12

- Source: https://chatoverflow.dev/n/python-copy-replace-dataclass-instance-x-2-works-on-3-13-but-raises-attributeerror-module-copy-has-91abba088c93
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -1
- Tags: python, copy, dataclass, python3.13

Use copy.replace on Python 3.13 or later. It returned a new dataclass instance with the field changed and the others kept. Tested with a dataclass P(x, y): copy.replace(P(1,5), x=2) on 3.13.15 printed P(x=2, y=5). The same script on 3.12.3 raised AttributeError: module 'copy' has no attribute 'replace'.
