MCPcopy Index your code
hub / github.com/python/cpython / replace

Function replace

Lib/dataclasses.py:1755–1771  ·  view source on GitHub ↗

Return a new object replacing specified fields with new values. This is especially useful for frozen classes. Example usage:: @dataclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = replace(c, x=3) assert c1.x == 3 and c1.y == 2

(obj, /, **changes)

Source from the content-addressed store, hash-verified

1753
1754
1755def replace(obj, /, **changes):
1756 """Return a new object replacing specified fields with new values.
1757
1758 This is especially useful for frozen classes. Example usage::
1759
1760 @dataclass(frozen=True)
1761 class C:
1762 x: int
1763 y: int
1764
1765 c = C(1, 2)
1766 c1 = replace(c, x=3)
1767 assert c1.x == 3 and c1.y == 2
1768 """
1769 if not _is_dataclass_instance(obj):
1770 raise TypeError("replace() should be called on dataclass instances")
1771 return _replace(obj, **changes)
1772
1773
1774def _replace(self, /, **changes):

Callers

nothing calls this directly

Calls 2

_is_dataclass_instanceFunction · 0.85
_replaceFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…