TIL about `copy.replace()` in Python 3.13
Trying to edit a NamedTuple or frozen dataclass in Python is much simpler now: there's a new `__replace__` method on them, and the right API to use it is:
>>> v
Vector(x=1, y=2)
>>> import copy
>>> copy.replace(v, x=3)
Vector(x=3, y=2)
over 1 year ago