Skip to content

Commit

Permalink
mark type_spec_is_assignable hidden (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Oct 21, 2022
1 parent 88f7b3a commit cf32c36
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Unreleased

## Added
* Added `abi.type_spec_is_assignable_to` to check for compatible ABI type assignments. ([#540](https://github.com/algorand/pyteal/pull/540))
* Added option to `OpUp` utility to allow specification of source for fees ([566](https://github.com/algorand/pyteal/pull/566))

## Fixed
Expand Down
2 changes: 0 additions & 2 deletions pyteal/ast/abi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
type_spec_from_algosdk,
type_specs_from_signature,
contains_type_spec,
type_spec_is_assignable_to,
)

__all__ = [
Expand Down Expand Up @@ -170,5 +169,4 @@
"algosdk_from_annotation",
"algosdk_from_type_spec",
"contains_type_spec",
"type_spec_is_assignable_to",
]
6 changes: 4 additions & 2 deletions pyteal/ast/abi/tuple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@ def test_NamedTuple_getitem(test_case: type[abi.NamedTuple]):


def test_NamedTupleTypeSpec():
from pyteal.ast.abi.util import type_spec_is_assignable_to

class Point(abi.NamedTuple):
x: abi.Field[abi.Uint64]
y: abi.Field[abi.Uint64]
Expand All @@ -942,5 +944,5 @@ class AccountRecord(abi.NamedTuple):
assert p.type_spec() == p.type_spec()
assert ar.type_spec() == ar.type_spec()
assert p.type_spec() != ar.type_spec()
assert not abi.type_spec_is_assignable_to(p.type_spec(), ar.type_spec())
assert not abi.type_spec_is_assignable_to(ar.type_spec(), p.type_spec())
assert not type_spec_is_assignable_to(p.type_spec(), ar.type_spec())
assert not type_spec_is_assignable_to(ar.type_spec(), p.type_spec())
13 changes: 7 additions & 6 deletions pyteal/ast/abi/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
substring_for_decoding,
int_literal_from_annotation,
type_spec_from_algosdk,
type_spec_is_assignable_to,
)

options = pt.CompileOptions(version=5)
Expand Down Expand Up @@ -861,7 +862,7 @@ def test_type_spec_is_assignable_safe_bidirectional(tc: SafeBidirectional):
assert len(tc.xs) > 0
for a in tc.xs:
for b in tc.xs:
assert abi.type_spec_is_assignable_to(a, b)
assert type_spec_is_assignable_to(a, b)


@pytest.mark.parametrize("ts", bfs_on_inheritance(abi.TypeSpec))
Expand Down Expand Up @@ -934,8 +935,8 @@ class SafeAssignment(NamedTuple):
def test_type_spec_is_assignable_safe_assignment(tc: SafeAssignment):
assert len(tc.bs) > 0
for b in tc.bs:
assert abi.type_spec_is_assignable_to(tc.a, b)
assert not abi.type_spec_is_assignable_to(b, tc.a)
assert type_spec_is_assignable_to(tc.a, b)
assert not type_spec_is_assignable_to(b, tc.a)


@pytest.mark.parametrize("ts", bfs_on_inheritance(abi.TypeSpec))
Expand Down Expand Up @@ -1037,10 +1038,10 @@ def test_type_spec_is_assignable_unsafe_bidirectional(tc: UnsafeBidirectional):
for ia, a in enumerate(tc.xs):
for ib, b in enumerate(tc.xs):
if ia == ib:
assert abi.type_spec_is_assignable_to(a, b)
assert abi.type_spec_is_assignable_to(b, a)
assert type_spec_is_assignable_to(a, b)
assert type_spec_is_assignable_to(b, a)
continue
assert not abi.type_spec_is_assignable_to(a, b)
assert not type_spec_is_assignable_to(a, b)


@pytest.mark.parametrize("ts", bfs_on_inheritance(abi.TypeSpec))
Expand Down
8 changes: 4 additions & 4 deletions pyteal/ast/itxn.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def MethodCall(
field being set. These fields are set on the ApplicationCallTransaction being constructed
"""

from pyteal.ast.abi.util import type_spec_is_assignable_to

require_type(app_id, TealType.uint64)

# Default, always need these
Expand Down Expand Up @@ -388,7 +390,7 @@ def MethodCall(
txntype = cast(EnumInt, arg[TxnField.type_enum]).name
# If the arg is an unspecified transaction, no need to check the type_enum

if not abi.type_spec_is_assignable_to(
if not type_spec_is_assignable_to(
abi.type_spec_from_algosdk(txntype), method_arg_ts
):
raise TealInputError(
Expand Down Expand Up @@ -460,9 +462,7 @@ def MethodCall(
require_type(arg, TealType.bytes)
app_args.append(arg)
elif isinstance(arg, abi.BaseType):
if not abi.type_spec_is_assignable_to(
arg.type_spec(), method_arg_ts
):
if not type_spec_is_assignable_to(arg.type_spec(), method_arg_ts):
raise TealTypeError(arg.type_spec(), method_arg_ts)
app_args.append(arg.encode())
else:
Expand Down
4 changes: 3 additions & 1 deletion pyteal/ast/subroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def invoke(
self,
args: list[Expr | ScratchVar | abi.BaseType],
) -> "SubroutineCall":
from pyteal.ast.abi.util import type_spec_is_assignable_to

if len(args) != self.argument_count():
raise TealInputError(
f"Incorrect number of arguments for subroutine call. "
Expand All @@ -283,7 +285,7 @@ def invoke(
f"supplied argument at index {i} should be an ABI type but got {arg}"
)

if not abi.type_spec_is_assignable_to(arg.type_spec(), arg_type):
if not type_spec_is_assignable_to(arg.type_spec(), arg_type):
raise TealInputError(
f"supplied argument {arg} at index {i} "
f"should have ABI typespec {arg_type} but got {arg.type_spec()}"
Expand Down

0 comments on commit cf32c36

Please sign in to comment.