jcrist · GitHub

@jcrist

This adds a new `msgspec.replace` function, mirroring the functionality
of `dataclasses.replace`/`NamedTuple._replace`/`attrs.evolve`. It takes
an existing `Struct` instance, and returns a copy with any fields passed
as `**changes` replacing the original values.
Note that:
- This works on any struct (including frozen structs), since this
  returns a new instance rather than mutating the old instance.
- This doesn't do a deepcopy of any of the field values. If the input
  struct had a list on a field, the output struct will have the same
  instance of that list (unless that field was passed in `**changes`).

Read the original on github.com ↗