MCPcopy Index your code
hub / github.com/RustPython/RustPython / replace

Function replace

Lib/dataclasses.py:1754–1770  ·  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

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

Callers

nothing calls this directly

Calls 2

_is_dataclass_instanceFunction · 0.85
_replaceFunction · 0.70

Tested by

no test coverage detected