MCPcopy
hub / github.com/django/django / replace

Function replace

django/utils/copy.py:7–17  ·  view source on GitHub ↗

Return a new object replacing specified fields with new values. This is especially useful for immutable objects, like named tuples or frozen dataclasses.

(obj, /, **changes)

Source from the content-addressed store, hash-verified

5else:
6 # Backport of copy.replace() from Python 3.13.
7 def replace(obj, /, **changes):
8 """Return a new object replacing specified fields with new values.
9
10 This is especially useful for immutable objects, like named tuples or
11 frozen dataclasses.
12 """
13 cls = obj.__class__
14 func = getattr(cls, "__replace__", None)
15 if func is None:
16 raise TypeError(f"replace() does not support {cls.__name__} objects")
17 return func(obj, **changes)

Callers 9

reduceMethod · 0.90
reduceMethod · 0.90
reduceMethod · 0.90
reduceMethod · 0.90
reduceMethod · 0.90
reduceMethod · 0.90
reduceMethod · 0.90
reduceMethod · 0.90
usingMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected