-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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
Proposed Changes
to_native
methods inarc4.StaticArray
andarc4.DynamicArray