Skip to content

Commit

Permalink
feat: add algopy.arc4.Struct._replace introduced in algorand-python…
Browse files Browse the repository at this point in the history
… 2.5.0
  • Loading branch information
daniel-makerx committed Feb 19, 2025
1 parent 8d47912 commit 75d6847
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/_algopy_testing/arc4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,12 @@ def _as_tuple(self) -> Tuple: # type: ignore[type-arg]
tuple_items = tuple(getattr(self, field.name) for field in dataclasses.fields(self))
return Tuple(tuple_items)

def _replace(self, **kwargs: typing.Any) -> typing.Self:
copy = self.copy()
for field, value in kwargs.items():
setattr(copy, field, value)
return copy


class ARC4Client:
pass
Expand Down
10 changes: 10 additions & 0 deletions tests/arc4/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,16 @@ def test_struct_kw_only() -> None:
StructWithKwOnly(arc4.UInt64(1), arc4.UInt64(2), arc4.Bool(True), arc4.String("hello")) # type: ignore[misc]


def test_replace() -> None:
x = StructWithKwOnly(
a=arc4.UInt64(1), b=arc4.UInt64(2), c=arc4.Bool(True), d=arc4.String("hello")
)
y = x._replace(a=arc4.UInt64(2))
assert x.a == arc4.UInt64(1)
assert y.a == arc4.UInt64(2)
assert x != y


def _compare_abi_and_arc4_values(
arc4_value: typing.Any,
abi_value: typing.Any,
Expand Down

0 comments on commit 75d6847

Please sign in to comment.