Skip to content
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

Optionally refactor handling of array_length int subclasses in StaticArrayTypeSpec #347

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyteal/ast/abi/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AddressLength(IntEnum):

class AddressTypeSpec(StaticArrayTypeSpec):
def __init__(self) -> None:
super().__init__(ByteTypeSpec(), int(AddressLength.Bytes))
super().__init__(ByteTypeSpec(), AddressLength.Bytes)

def new_instance(self) -> "Address":
return Address()
Expand Down Expand Up @@ -67,7 +67,7 @@ def set(
case ComputedValue():
pts = value.produced_type_spec()
if pts == AddressTypeSpec() or pts == StaticArrayTypeSpec(
ByteTypeSpec(), int(AddressLength.Bytes)
ByteTypeSpec(), AddressLength.Bytes
):
return value.store_into(self)

Expand All @@ -78,7 +78,7 @@ def set(
if (
value.type_spec() == AddressTypeSpec()
or value.type_spec()
== StaticArrayTypeSpec(ByteTypeSpec(), int(AddressLength.Bytes))
== StaticArrayTypeSpec(ByteTypeSpec(), AddressLength.Bytes)
):
return self.stored_value.store(value.stored_value.load())

Expand Down
4 changes: 3 additions & 1 deletion pyteal/ast/abi/array_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def __init__(self, value_type_spec: TypeSpec, array_length: int) -> None:
super().__init__(value_type_spec)
if not isinstance(array_length, int) or array_length < 0:
raise TypeError(f"Unsupported StaticArray length: {array_length}")
self.array_length: Final = array_length

# Casts to `int` to handle downstream usage where value is a subclass of int like `IntEnum`.
self.array_length: Final = int(array_length)

def new_instance(self) -> "StaticArray[T, N]":
return StaticArray(self)
Expand Down