Skip to content

feat: add stub implementations of array types #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boblat
Copy link
Contributor

@boblat boblat commented Jul 21, 2025

Proposed Changes

  • rename Array to ReferenceArray
  • add stub implementations for
    • Array
    • FixedArray
    • ImmutableArray
    • ImmutableFixedArray
    • Struct
    • zero_bytes
  • add stub implementations of to_native methods in arc4.StaticArray and arc4.DynamicArray

@@ -132,7 +132,7 @@ dependencies = [
"pytest-cov>=4.1.0",
"py-algorand-sdk>=2.4.0",
"algokit-utils>=3.0.0",
"puyapy>=3.0",
"puyapy @ {root:parent:uri}/puya",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: undo these once a new version of puyapy is released.

@@ -30,7 +30,7 @@ dependencies = [
"pynacl>=1.4.0,<2",
"ecdsa>=0.17.0",
"coincurve>=19.0.1",
"algorand-python>=2.0"
"algorand-python @ file://{root}/../puya/stubs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: undo these once a new version of algorand-python is released.

assert cls._element_type
except AttributeError:
try:
items = list(values)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move items assignment out of try block


def __getitem__(self, index: UInt64 | int) -> _TArrayItem:
value = self._items[index]
return set_item_on_mutate(self, index, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't need set_item_on_mutate for Immutable arrays as the element types are also required to be immutable


def __new__(cls, values: Iterable[_TArrayItem]) -> typing.Self:
try:
assert cls._element_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use if not hasattr() here instead?


@classmethod
def full(cls, item: _TArrayItem) -> typing.Self:
return cls(item for _ in range(cls._length))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return cls(item for _ in range(cls._length))
return cls([item] * cls._length)

return UInt64(len(self._items))

def __len__(self) -> UInt64:
return self.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure python requires __len__ to always return an int (which is why we couldn't support the len builtin in python), should do this for the other Array types too

Suggested change
return self.length
return len(self._items)


def __getitem__(self, index: UInt64 | int) -> _TArrayItem:
value = self._items[index]
return set_item_on_mutate(self, index, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this on ImmutableArray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants