From c56b462ebb39573aad3fdfab654dfb548fd5bc4b Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Fri, 22 Apr 2022 09:03:11 -0400 Subject: [PATCH] fmt --- pyteal/ast/abi/address.py | 23 +++++++++++++++++++---- pyteal/ast/abi/string.py | 22 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/pyteal/ast/abi/address.py b/pyteal/ast/abi/address.py index cd4a6159c..f541d71a9 100644 --- a/pyteal/ast/abi/address.py +++ b/pyteal/ast/abi/address.py @@ -13,6 +13,7 @@ T = TypeVar("T", bound=BaseType) N = TypeVar("N", bound=int) + class AddressTypeSpec(StaticArrayTypeSpec): def __init__(self) -> None: super().__init__(ByteTypeSpec(), ADDRESS_LENGTH) @@ -40,16 +41,30 @@ def type_spec(self) -> AddressTypeSpec: def get(self) -> Expr: return self.stored_value.load() - def set(self, value: Union[Sequence[T], StaticArray[T, N], ComputedValue[StaticArray[T, N]], "Address", str, Expr]): - + def set( + self, + value: Union[ + Sequence[T], + StaticArray[T, N], + ComputedValue[StaticArray[T, N]], + "Address", + str, + Expr, + ], + ): + if isinstance(value, ComputedValue): if value.produced_type_spec() is not AddressTypeSpec(): - raise TealInputError(f"Got ComputedValue with type spec {value.produced_type_spec()}, expected AddressTypeSpec") + raise TealInputError( + f"Got ComputedValue with type spec {value.produced_type_spec()}, expected AddressTypeSpec" + ) return value.store_into(self) if isinstance(value, BaseType): if value.type_spec() is not AddressTypeSpec(): - raise TealInputError(f"Got {value.__class__} with type spec {value.type_spec()}, expected AddressTypeSpec") + raise TealInputError( + f"Got {value.__class__} with type spec {value.type_spec()}, expected AddressTypeSpec" + ) return self.decode(self.encode()) if isinstance(value, str): diff --git a/pyteal/ast/abi/string.py b/pyteal/ast/abi/string.py index 2b3b990b0..d15bbdd8c 100644 --- a/pyteal/ast/abi/string.py +++ b/pyteal/ast/abi/string.py @@ -22,8 +22,10 @@ def encoded_string(s: Expr): return Concat(Suffix(Itob(Len(s)), Int(6)), s) + T = TypeVar("T", bound=BaseType) + class StringTypeSpec(DynamicArrayTypeSpec): def __init__(self) -> None: super().__init__(ByteTypeSpec()) @@ -53,17 +55,31 @@ def get(self) -> Expr: self.stored_value.load(), Int(Uint16TypeSpec().byte_length_static()) ) - def set(self, value: Union[Sequence[T], DynamicArray[T], ComputedValue[DynamicArray[T]], "String", str, Expr]) -> Expr: + def set( + self, + value: Union[ + Sequence[T], + DynamicArray[T], + ComputedValue[DynamicArray[T]], + "String", + str, + Expr, + ], + ) -> Expr: # Assume length prefixed if isinstance(value, ComputedValue): if value.produced_type_spec() is not StringTypeSpec(): - raise TealInputError(f"Got ComputedValue with type spec {value.produced_type_spec()}, expected StringTypeSpec") + raise TealInputError( + f"Got ComputedValue with type spec {value.produced_type_spec()}, expected StringTypeSpec" + ) return value.store_into(self) if isinstance(value, BaseType): if value.type_spec() is not StringTypeSpec(): - raise TealInputError(f"Got {value.__class__} with type spec {value.type_spec()}, expected StringTypeSpec") + raise TealInputError( + f"Got {value.__class__} with type spec {value.type_spec()}, expected StringTypeSpec" + ) return value.decode(value.encode()) # Assume not length prefixed