Skip to content

Commit 75d6847

Browse files
committed
feat: add algopy.arc4.Struct._replace introduced in algorand-python 2.5.0
1 parent 8d47912 commit 75d6847

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/_algopy_testing/arc4.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@ def _as_tuple(self) -> Tuple: # type: ignore[type-arg]
10961096
tuple_items = tuple(getattr(self, field.name) for field in dataclasses.fields(self))
10971097
return Tuple(tuple_items)
10981098

1099+
def _replace(self, **kwargs: typing.Any) -> typing.Self:
1100+
copy = self.copy()
1101+
for field, value in kwargs.items():
1102+
setattr(copy, field, value)
1103+
return copy
1104+
10991105

11001106
class ARC4Client:
11011107
pass

tests/arc4/test_struct.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ def test_struct_kw_only() -> None:
349349
StructWithKwOnly(arc4.UInt64(1), arc4.UInt64(2), arc4.Bool(True), arc4.String("hello")) # type: ignore[misc]
350350

351351

352+
def test_replace() -> None:
353+
x = StructWithKwOnly(
354+
a=arc4.UInt64(1), b=arc4.UInt64(2), c=arc4.Bool(True), d=arc4.String("hello")
355+
)
356+
y = x._replace(a=arc4.UInt64(2))
357+
assert x.a == arc4.UInt64(1)
358+
assert y.a == arc4.UInt64(2)
359+
assert x != y
360+
361+
352362
def _compare_abi_and_arc4_values(
353363
arc4_value: typing.Any,
354364
abi_value: typing.Any,

0 commit comments

Comments
 (0)