-
Notifications
You must be signed in to change notification settings - Fork 131
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
Applying type_spec_abi_is_assignable_to
to ABI
computed type
#567
Changes from all commits
dac3abe
ea8fab6
d6f1de2
6da7ab4
3e776f8
885f38c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from enum import IntEnum | ||
from typing import Union, Sequence, Literal, cast | ||
from typing import Sequence, Literal, cast | ||
from collections.abc import Sequence as CollectionSequence | ||
|
||
from pyteal.errors import TealInputError | ||
|
@@ -13,6 +13,7 @@ | |
from pyteal.ast.abi.type import ComputedValue, BaseType | ||
from pyteal.ast.abi.array_static import StaticArray, StaticArrayTypeSpec | ||
from pyteal.ast.abi.uint import ByteTypeSpec, Byte | ||
from pyteal.ast.abi.util import type_spec_is_assignable_to | ||
from pyteal.ast.expr import Expr | ||
|
||
|
||
|
@@ -58,18 +59,14 @@ def get(self) -> Expr: | |
""" | ||
return self.stored_value.load() | ||
|
||
def set( | ||
def set( # type: ignore[override] | ||
self, | ||
value: Union[ | ||
str, | ||
bytes, | ||
Expr, | ||
Sequence[Byte], | ||
StaticArray[Byte, Literal[AddressLength.Bytes]], | ||
ComputedValue[StaticArray[Byte, Literal[AddressLength.Bytes]]], | ||
"Address", | ||
ComputedValue["Address"], | ||
], | ||
value: str | ||
| bytes | ||
| Expr | ||
| Sequence[Byte] | ||
| "Address" | ||
| ComputedValue["Address"], | ||
): | ||
"""Set the value of this Address to the input value. | ||
|
||
|
@@ -93,21 +90,9 @@ def set( | |
|
||
match value: | ||
case ComputedValue(): | ||
pts = value.produced_type_spec() | ||
if pts == AddressTypeSpec() or pts == StaticArrayTypeSpec( | ||
ByteTypeSpec(), AddressLength.Bytes | ||
): | ||
return value.store_into(self) | ||
|
||
raise TealInputError( | ||
f"Got ComputedValue with type spec {pts}, expected AddressTypeSpec or StaticArray[Byte, Literal[AddressLength.Bytes]]" | ||
) | ||
return self._set_with_computed_type(value) | ||
case BaseType(): | ||
if ( | ||
value.type_spec() == AddressTypeSpec() | ||
or value.type_spec() | ||
== StaticArrayTypeSpec(ByteTypeSpec(), AddressLength.Bytes) | ||
): | ||
if type_spec_is_assignable_to(value.type_spec(), AddressTypeSpec()): | ||
return self.stored_value.store(value.stored_value.load()) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahangsu Unrelated to the line - Based on the PR's changes, the Not requesting an immediate change because there's more pressing threads open. I leave the question to avoid forgetting the concern prior to merge. |
||
raise TealInputError( | ||
|
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.
I'm not sure which is preferable - What do folks think?
Options:
cast
method.During our live discussion yesterday, I didn't realize the type error will happen. It feels to me like we should not ignore the error.
Another alternative (that's more expansive in scope) is to rework
Address
so that it extendsTypeSpec
and uses composition for value storage/retrieval.