From efbe1e55f7c7f50129103a3147a955b1238829f1 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 14 Apr 2022 15:32:41 -0400 Subject: [PATCH 01/11] adding string and address types --- pyteal/ast/abi/__init__.py | 5 ++++ pyteal/ast/abi/string.py | 55 ++++++++++++++++++++++++++++++++++++++ pyteal/ast/abi/util.py | 11 ++++++++ 3 files changed, 71 insertions(+) create mode 100644 pyteal/ast/abi/string.py diff --git a/pyteal/ast/abi/__init__.py b/pyteal/ast/abi/__init__.py index e2d57bf29..2fecd481d 100644 --- a/pyteal/ast/abi/__init__.py +++ b/pyteal/ast/abi/__init__.py @@ -1,3 +1,4 @@ +from .string import String, Address, StringTypeSpec, AddressTypeSpec from .type import TypeSpec, BaseType, ComputedValue from .bool import BoolTypeSpec, Bool from .uint import ( @@ -32,6 +33,10 @@ from .method_return import MethodReturn __all__ = [ + "String", + "StringTypeSpec", + "Address", + "AddressTypeSpec", "TypeSpec", "BaseType", "ComputedValue", diff --git a/pyteal/ast/abi/string.py b/pyteal/ast/abi/string.py new file mode 100644 index 000000000..3b806b7c2 --- /dev/null +++ b/pyteal/ast/abi/string.py @@ -0,0 +1,55 @@ +from .array_static import StaticArray, StaticArrayTypeSpec +from .array_dynamic import DynamicArray, DynamicArrayTypeSpec +from .uint import ByteTypeSpec + +address_length = 32 + + +class AddressTypeSpec(StaticArrayTypeSpec): + def __init__(self) -> None: + super().__init__(ByteTypeSpec, address_length) + + def new_instance(self) -> "Address": + return Address() + + def __str__(self) -> str: + return "address" + + +AddressTypeSpec.__module__ = "pyteal" + + +class Address(StaticArray): + def __init__(self) -> None: + super().__init__(AddressTypeSpec(), address_length) + + def type_spec(self) -> AddressTypeSpec: + return AddressTypeSpec() + + +Address.__module__ = "pyteal" + + +class StringTypeSpec(DynamicArrayTypeSpec): + def __init__(self) -> None: + super().__init__(ByteTypeSpec) + + def new_instance(self) -> "String": + return String() + + def __str__(self) -> str: + return "string" + + +StringTypeSpec.__module__ = "pyteal" + + +class String(DynamicArray): + def __init__(self) -> None: + super().__init__(StringTypeSpec()) + + def type_spec(self) -> StringTypeSpec: + return StringTypeSpec() + + +String.__module__ = "pyteal" diff --git a/pyteal/ast/abi/util.py b/pyteal/ast/abi/util.py index e9077ded6..89876e751 100644 --- a/pyteal/ast/abi/util.py +++ b/pyteal/ast/abi/util.py @@ -107,6 +107,7 @@ def type_spec_from_annotation(annotation: Any) -> TypeSpec: Tuple4, Tuple5, ) + from .string import String, Address, StringTypeSpec, AddressTypeSpec origin = get_origin(annotation) if origin is None: @@ -144,6 +145,16 @@ def type_spec_from_annotation(annotation: Any) -> TypeSpec: raise TypeError("Uint64 expects 0 type arguments. Got: {}".format(args)) return Uint64TypeSpec() + if origin is String: + if len(args) != 0: + raise TypeError("String expects 0 arguments. Got: {}".format(args)) + return StringTypeSpec() + + if origin is Address: + if len(args) != 0: + raise TypeError("Address expects 0 arguments. Got: {}".format(args)) + return AddressTypeSpec() + if origin is DynamicArray: if len(args) != 1: raise TypeError( From 7db17ca402fcf9551028ce4183748ce3897d6309 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 14 Apr 2022 16:30:28 -0400 Subject: [PATCH 02/11] fix type spec, added get and thoughts on set --- pyteal/ast/abi/string.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pyteal/ast/abi/string.py b/pyteal/ast/abi/string.py index 3b806b7c2..043ae12f0 100644 --- a/pyteal/ast/abi/string.py +++ b/pyteal/ast/abi/string.py @@ -1,13 +1,17 @@ from .array_static import StaticArray, StaticArrayTypeSpec from .array_dynamic import DynamicArray, DynamicArrayTypeSpec from .uint import ByteTypeSpec +from .util import substringForDecoding + +from ..int import Int +from ..expr import Expr address_length = 32 class AddressTypeSpec(StaticArrayTypeSpec): def __init__(self) -> None: - super().__init__(ByteTypeSpec, address_length) + super().__init__(ByteTypeSpec(), address_length) def new_instance(self) -> "Address": return Address() @@ -26,13 +30,16 @@ def __init__(self) -> None: def type_spec(self) -> AddressTypeSpec: return AddressTypeSpec() + def get(self) -> Expr: + return self.stored_value.load() + Address.__module__ = "pyteal" class StringTypeSpec(DynamicArrayTypeSpec): def __init__(self) -> None: - super().__init__(ByteTypeSpec) + super().__init__(ByteTypeSpec()) def new_instance(self) -> "String": return String() @@ -51,5 +58,8 @@ def __init__(self) -> None: def type_spec(self) -> StringTypeSpec: return StringTypeSpec() + def get(self) -> Expr: + return substringForDecoding(self.stored_value.load(), startIndex=Int(2)) + String.__module__ = "pyteal" From 40554243f48ed3455684dd399a7ffff3d5fd680b Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Fri, 15 Apr 2022 08:33:09 -0400 Subject: [PATCH 03/11] move address to its own file, starting to add tests --- pyteal/ast/abi/__init__.py | 3 +- pyteal/ast/abi/address.py | 33 ++++++++++++++ pyteal/ast/abi/address_test.py | 78 ++++++++++++++++++++++++++++++++++ pyteal/ast/abi/string.py | 17 ++++++++ pyteal/ast/abi/string_test.py | 33 ++++++++++++++ pyteal/ast/abi/util.py | 3 +- 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 pyteal/ast/abi/address.py create mode 100644 pyteal/ast/abi/address_test.py create mode 100644 pyteal/ast/abi/string_test.py diff --git a/pyteal/ast/abi/__init__.py b/pyteal/ast/abi/__init__.py index 2fecd481d..aa670ce4f 100644 --- a/pyteal/ast/abi/__init__.py +++ b/pyteal/ast/abi/__init__.py @@ -1,4 +1,5 @@ -from .string import String, Address, StringTypeSpec, AddressTypeSpec +from .string import String, StringTypeSpec +from .address import AddressTypeSpec, Address from .type import TypeSpec, BaseType, ComputedValue from .bool import BoolTypeSpec, Bool from .uint import ( diff --git a/pyteal/ast/abi/address.py b/pyteal/ast/abi/address.py new file mode 100644 index 000000000..83bf9682e --- /dev/null +++ b/pyteal/ast/abi/address.py @@ -0,0 +1,33 @@ +from .array_static import StaticArray, StaticArrayTypeSpec +from .uint import ByteTypeSpec +from ..expr import Expr + +address_length = 32 + + +class AddressTypeSpec(StaticArrayTypeSpec): + def __init__(self) -> None: + super().__init__(ByteTypeSpec(), address_length) + + def new_instance(self) -> "Address": + return Address() + + def __str__(self) -> str: + return "address" + + +AddressTypeSpec.__module__ = "pyteal" + + +class Address(StaticArray): + def __init__(self) -> None: + super().__init__(AddressTypeSpec(), address_length) + + def type_spec(self) -> AddressTypeSpec: + return AddressTypeSpec() + + def get(self) -> Expr: + return self.stored_value.load() + + +Address.__module__ = "pyteal" diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py new file mode 100644 index 000000000..8f4e2ff29 --- /dev/null +++ b/pyteal/ast/abi/address_test.py @@ -0,0 +1,78 @@ +from .type_test import ContainerType +from os import urandom + +from ... import * + +options = CompileOptions(version=5) + +def test_AddressTypeSpec_str(): + assert str(abi.AddressTypeSpec()) == "address" + +def test_AddressTypeSpec_is_dynamic(): + assert not (abi.AddressTypeSpec()).is_dynamic() + +def test_AddressTypeSpec_is_dynamic(): + assert (abi.AddressTypeSpec()).byte_length_static() == 32 + +def test_AddressTypeSpec_new_instance(): + assert isinstance(abi.AddressTypeSpec().new_instance(), abi.Address) + +def test_AddressTypeSpec_eq(): + assert abi.AddressTypeSpec() == abi.AddressTypeSpec() + + for otherType in ( + abi.ByteTypeSpec, + abi.StaticArrayTypeSpec(abi.ByteTypeSpec(), 31), + abi.DynamicArrayTypeSpec(abi.ByteTypeSpec()), + ): + assert abi.AddressTypeSpec() != otherType + +def test_Address_encode(): + value = abi.Address() + expr = value.encode() + assert expr.type_of() == TealType.bytes + assert not expr.has_return() + + expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) + actual, _ = expr.__teal__(options) + assert actual == expected + +def test_Address_decode(): + value = abi.Address() + for value_to_set in [urandom(32) for x in range(10)]: + expr = value.decode(Bytes(value_to_set)) + + assert expr.type_of() == TealType.none + assert not expr.has_return() + + expected = TealSimpleBlock( + [ + TealOp(None, Op.byte, f"0x{value_to_set.hex()}"), + TealOp(None, Op.store, value.stored_value.slot) + ] + ) + actual, _ = expr.__teal__(options) + actual.addIncoming() + actual = TealBlock.NormalizeBlocks(actual) + + with TealComponent.Context.ignoreExprEquality(): + assert actual == expected + +#def test_Address_set_static(): +# value = abi.Address() +# for value_to_set in [urandom(32) for x in range(10)]: +# print(value_to_set) +# expr = value.set(Bytes(value_to_set)) +# +# assert expr.type_of() == TealType.none +# assert not expr.has_return() + +def test_Address_get(): + value = abi.Address() + expr = value.get() + assert expr.type_of() == TealType.bytes + assert not expr.has_return() + + expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) + actual, _ = expr.__teal__(options) + assert actual == expected \ No newline at end of file diff --git a/pyteal/ast/abi/string.py b/pyteal/ast/abi/string.py index 043ae12f0..8a146df16 100644 --- a/pyteal/ast/abi/string.py +++ b/pyteal/ast/abi/string.py @@ -1,3 +1,4 @@ +from typing import Union from .array_static import StaticArray, StaticArrayTypeSpec from .array_dynamic import DynamicArray, DynamicArrayTypeSpec from .uint import ByteTypeSpec @@ -61,5 +62,21 @@ def type_spec(self) -> StringTypeSpec: def get(self) -> Expr: return substringForDecoding(self.stored_value.load(), startIndex=Int(2)) + def __getslice__(self, low: Union[int, Int], high: Union[int, Int]): + if type(low) is int: + low = Int(low) + + if type(high) is int: + high = Int(high) + + if not isinstance(low, Int): + raise TypeError("low expected int or Int, got {low}") + if not isinstance(high, Int): + raise TypeError("high expected int or Int, got {high}") + + + return substringForDecoding(self.stored_value.load(), startIndex=Int(2)+low, endIndex=Int(2)+high) + + String.__module__ = "pyteal" diff --git a/pyteal/ast/abi/string_test.py b/pyteal/ast/abi/string_test.py new file mode 100644 index 000000000..12d584b19 --- /dev/null +++ b/pyteal/ast/abi/string_test.py @@ -0,0 +1,33 @@ +from .type_test import ContainerType +from os import urandom + +from ... import * + +import pytest + +options = CompileOptions(version=5) + + +def test_String_encode(): + value = abi.String() + + tspec = value.type_spec() + assert tspec.is_dynamic() + assert str(tspec) == "string" + + expr = value.encode() + assert expr.type_of() == TealType.bytes + assert not expr.has_return() + + + expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) + actual, _ = expr.__teal__(options) + assert actual == expected + assert expr == value.get() + + +def test_String_decode(): + pass + +def test_String_get(): + pass diff --git a/pyteal/ast/abi/util.py b/pyteal/ast/abi/util.py index 89876e751..4ebee5301 100644 --- a/pyteal/ast/abi/util.py +++ b/pyteal/ast/abi/util.py @@ -107,7 +107,8 @@ def type_spec_from_annotation(annotation: Any) -> TypeSpec: Tuple4, Tuple5, ) - from .string import String, Address, StringTypeSpec, AddressTypeSpec + from .string import StringTypeSpec, String + from .address import AddressTypeSpec, Address origin = get_origin(annotation) if origin is None: From 12a36a687e8622753cc06ed3d2a52a4f1ebd4542 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Fri, 15 Apr 2022 08:45:11 -0400 Subject: [PATCH 04/11] adding tests for string --- pyteal/ast/abi/address_test.py | 36 +++++++++------ pyteal/ast/abi/string.py | 36 ++------------- pyteal/ast/abi/string_test.py | 84 ++++++++++++++++++++++++++++------ pyteal/ast/abi/util.py | 2 +- 4 files changed, 97 insertions(+), 61 deletions(-) diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py index 8f4e2ff29..806050fa7 100644 --- a/pyteal/ast/abi/address_test.py +++ b/pyteal/ast/abi/address_test.py @@ -1,22 +1,26 @@ from .type_test import ContainerType -from os import urandom from ... import * options = CompileOptions(version=5) + def test_AddressTypeSpec_str(): assert str(abi.AddressTypeSpec()) == "address" - + + def test_AddressTypeSpec_is_dynamic(): assert not (abi.AddressTypeSpec()).is_dynamic() -def test_AddressTypeSpec_is_dynamic(): + +def test_AddressTypeSpec_byte_length_static(): assert (abi.AddressTypeSpec()).byte_length_static() == 32 + def test_AddressTypeSpec_new_instance(): assert isinstance(abi.AddressTypeSpec().new_instance(), abi.Address) + def test_AddressTypeSpec_eq(): assert abi.AddressTypeSpec() == abi.AddressTypeSpec() @@ -27,6 +31,7 @@ def test_AddressTypeSpec_eq(): ): assert abi.AddressTypeSpec() != otherType + def test_Address_encode(): value = abi.Address() expr = value.encode() @@ -37,7 +42,10 @@ def test_Address_encode(): actual, _ = expr.__teal__(options) assert actual == expected + def test_Address_decode(): + from os import urandom + value = abi.Address() for value_to_set in [urandom(32) for x in range(10)]: expr = value.decode(Bytes(value_to_set)) @@ -48,7 +56,7 @@ def test_Address_decode(): expected = TealSimpleBlock( [ TealOp(None, Op.byte, f"0x{value_to_set.hex()}"), - TealOp(None, Op.store, value.stored_value.slot) + TealOp(None, Op.store, value.stored_value.slot), ] ) actual, _ = expr.__teal__(options) @@ -58,14 +66,6 @@ def test_Address_decode(): with TealComponent.Context.ignoreExprEquality(): assert actual == expected -#def test_Address_set_static(): -# value = abi.Address() -# for value_to_set in [urandom(32) for x in range(10)]: -# print(value_to_set) -# expr = value.set(Bytes(value_to_set)) -# -# assert expr.type_of() == TealType.none -# assert not expr.has_return() def test_Address_get(): value = abi.Address() @@ -75,4 +75,14 @@ def test_Address_get(): expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) actual, _ = expr.__teal__(options) - assert actual == expected \ No newline at end of file + assert actual == expected + + +# def test_Address_set_static(): +# value = abi.Address() +# for value_to_set in [urandom(32) for x in range(10)]: +# print(value_to_set) +# expr = value.set(Bytes(value_to_set)) +# +# assert expr.type_of() == TealType.none +# assert not expr.has_return() diff --git a/pyteal/ast/abi/string.py b/pyteal/ast/abi/string.py index 8a146df16..4d9883bef 100644 --- a/pyteal/ast/abi/string.py +++ b/pyteal/ast/abi/string.py @@ -7,36 +7,6 @@ from ..int import Int from ..expr import Expr -address_length = 32 - - -class AddressTypeSpec(StaticArrayTypeSpec): - def __init__(self) -> None: - super().__init__(ByteTypeSpec(), address_length) - - def new_instance(self) -> "Address": - return Address() - - def __str__(self) -> str: - return "address" - - -AddressTypeSpec.__module__ = "pyteal" - - -class Address(StaticArray): - def __init__(self) -> None: - super().__init__(AddressTypeSpec(), address_length) - - def type_spec(self) -> AddressTypeSpec: - return AddressTypeSpec() - - def get(self) -> Expr: - return self.stored_value.load() - - -Address.__module__ = "pyteal" - class StringTypeSpec(DynamicArrayTypeSpec): def __init__(self) -> None: @@ -74,9 +44,9 @@ def __getslice__(self, low: Union[int, Int], high: Union[int, Int]): if not isinstance(high, Int): raise TypeError("high expected int or Int, got {high}") - - return substringForDecoding(self.stored_value.load(), startIndex=Int(2)+low, endIndex=Int(2)+high) - + return substringForDecoding( + self.stored_value.load(), startIndex=Int(2) + low, endIndex=Int(2) + high + ) String.__module__ = "pyteal" diff --git a/pyteal/ast/abi/string_test.py b/pyteal/ast/abi/string_test.py index 12d584b19..c59f40b4d 100644 --- a/pyteal/ast/abi/string_test.py +++ b/pyteal/ast/abi/string_test.py @@ -1,33 +1,89 @@ -from .type_test import ContainerType -from os import urandom - from ... import * -import pytest - options = CompileOptions(version=5) -def test_String_encode(): - value = abi.String() +def test_StringTypeSpec_str(): + assert str(abi.StringTypeSpec()) == "string" + + +def test_StringTypeSpec_is_dynamic(): + assert (abi.StringTypeSpec()).is_dynamic() + - tspec = value.type_spec() - assert tspec.is_dynamic() - assert str(tspec) == "string" +def test_StringTypeSpec_new_instance(): + assert isinstance(abi.StringTypeSpec().new_instance(), abi.String) + +def test_StringTypeSpec_eq(): + assert abi.StringTypeSpec() == abi.StringTypeSpec() + + for otherType in ( + abi.ByteTypeSpec, + abi.StaticArrayTypeSpec(abi.ByteTypeSpec(), 1), + abi.DynamicArrayTypeSpec(abi.Uint8TypeSpec()), + ): + assert abi.StringTypeSpec() != otherType + + +def test_String_encode(): + value = abi.String() expr = value.encode() assert expr.type_of() == TealType.bytes assert not expr.has_return() - expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) actual, _ = expr.__teal__(options) assert actual == expected - assert expr == value.get() def test_String_decode(): - pass + import random + from os import urandom + + value = abi.String() + for value_to_set in [urandom(random.randint(0, 50)) for x in range(10)]: + expr = value.decode(Bytes(value_to_set)) + + assert expr.type_of() == TealType.none + assert not expr.has_return() + + expected = TealSimpleBlock( + [ + TealOp(None, Op.byte, f"0x{value_to_set.hex()}"), + TealOp(None, Op.store, value.stored_value.slot), + ] + ) + actual, _ = expr.__teal__(options) + actual.addIncoming() + actual = TealBlock.NormalizeBlocks(actual) + + with TealComponent.Context.ignoreExprEquality(): + assert actual == expected + def test_String_get(): - pass + value = abi.String() + expr = value.get() + assert expr.type_of() == TealType.bytes + assert not expr.has_return() + + expected = TealSimpleBlock( + [TealOp(expr, Op.load, value.stored_value.slot), TealOp(None, Op.extract, 2, 0)] + ) + actual, _ = expr.__teal__(options) + actual.addIncoming() + actual = TealBlock.NormalizeBlocks(actual) + + with TealComponent.Context.ignoreExprEquality(): + assert actual == expected + + +# def test_String_set_static(): +# value = abi.String() +# for value_to_set in [urandom(32) for x in range(10)]: +# print(value_to_set) +# expr = value.set(Bytes(value_to_set)) +# +# assert expr.type_of() == TealType.none +# assert not expr.has_return() diff --git a/pyteal/ast/abi/util.py b/pyteal/ast/abi/util.py index 4ebee5301..f16a03900 100644 --- a/pyteal/ast/abi/util.py +++ b/pyteal/ast/abi/util.py @@ -108,7 +108,7 @@ def type_spec_from_annotation(annotation: Any) -> TypeSpec: Tuple5, ) from .string import StringTypeSpec, String - from .address import AddressTypeSpec, Address + from .address import AddressTypeSpec, Address origin = get_origin(annotation) if origin is None: From af7967d530238c4c0fe2b4ceb9a4a38353a0f3a6 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Fri, 15 Apr 2022 12:14:59 -0400 Subject: [PATCH 05/11] removed unused tests --- pyteal/ast/abi/address_test.py | 10 ---------- pyteal/ast/abi/string.py | 21 +++------------------ pyteal/ast/abi/string_test.py | 10 ---------- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py index 806050fa7..345bb2b2e 100644 --- a/pyteal/ast/abi/address_test.py +++ b/pyteal/ast/abi/address_test.py @@ -76,13 +76,3 @@ def test_Address_get(): expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) actual, _ = expr.__teal__(options) assert actual == expected - - -# def test_Address_set_static(): -# value = abi.Address() -# for value_to_set in [urandom(32) for x in range(10)]: -# print(value_to_set) -# expr = value.set(Bytes(value_to_set)) -# -# assert expr.type_of() == TealType.none -# assert not expr.has_return() diff --git a/pyteal/ast/abi/string.py b/pyteal/ast/abi/string.py index 4d9883bef..6560bed22 100644 --- a/pyteal/ast/abi/string.py +++ b/pyteal/ast/abi/string.py @@ -1,7 +1,5 @@ -from typing import Union -from .array_static import StaticArray, StaticArrayTypeSpec from .array_dynamic import DynamicArray, DynamicArrayTypeSpec -from .uint import ByteTypeSpec +from .uint import ByteTypeSpec, Uint16TypeSpec from .util import substringForDecoding from ..int import Int @@ -30,22 +28,9 @@ def type_spec(self) -> StringTypeSpec: return StringTypeSpec() def get(self) -> Expr: - return substringForDecoding(self.stored_value.load(), startIndex=Int(2)) - - def __getslice__(self, low: Union[int, Int], high: Union[int, Int]): - if type(low) is int: - low = Int(low) - - if type(high) is int: - high = Int(high) - - if not isinstance(low, Int): - raise TypeError("low expected int or Int, got {low}") - if not isinstance(high, Int): - raise TypeError("high expected int or Int, got {high}") - return substringForDecoding( - self.stored_value.load(), startIndex=Int(2) + low, endIndex=Int(2) + high + self.stored_value.load(), + startIndex=Int(Uint16TypeSpec().byte_length_static()), ) diff --git a/pyteal/ast/abi/string_test.py b/pyteal/ast/abi/string_test.py index c59f40b4d..45da165fc 100644 --- a/pyteal/ast/abi/string_test.py +++ b/pyteal/ast/abi/string_test.py @@ -77,13 +77,3 @@ def test_String_get(): with TealComponent.Context.ignoreExprEquality(): assert actual == expected - - -# def test_String_set_static(): -# value = abi.String() -# for value_to_set in [urandom(32) for x in range(10)]: -# print(value_to_set) -# expr = value.set(Bytes(value_to_set)) -# -# assert expr.type_of() == TealType.none -# assert not expr.has_return() From 3e7fdfdcad5cf79097ce687873d121a4810fda8e Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Fri, 15 Apr 2022 12:51:46 -0400 Subject: [PATCH 06/11] cr --- pyteal/ast/abi/__init__.py | 3 ++- pyteal/ast/abi/address.py | 6 +++--- pyteal/ast/abi/address_test.py | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pyteal/ast/abi/__init__.py b/pyteal/ast/abi/__init__.py index aa670ce4f..0dfefb026 100644 --- a/pyteal/ast/abi/__init__.py +++ b/pyteal/ast/abi/__init__.py @@ -1,5 +1,5 @@ from .string import String, StringTypeSpec -from .address import AddressTypeSpec, Address +from .address import AddressTypeSpec, Address, ADDRESS_LENGTH from .type import TypeSpec, BaseType, ComputedValue from .bool import BoolTypeSpec, Bool from .uint import ( @@ -38,6 +38,7 @@ "StringTypeSpec", "Address", "AddressTypeSpec", + "ADDRESS_LENGTH", "TypeSpec", "BaseType", "ComputedValue", diff --git a/pyteal/ast/abi/address.py b/pyteal/ast/abi/address.py index 83bf9682e..0a95ab6f7 100644 --- a/pyteal/ast/abi/address.py +++ b/pyteal/ast/abi/address.py @@ -2,12 +2,12 @@ from .uint import ByteTypeSpec from ..expr import Expr -address_length = 32 +ADDRESS_LENGTH = 32 class AddressTypeSpec(StaticArrayTypeSpec): def __init__(self) -> None: - super().__init__(ByteTypeSpec(), address_length) + super().__init__(ByteTypeSpec(), ADDRESS_LENGTH) def new_instance(self) -> "Address": return Address() @@ -21,7 +21,7 @@ def __str__(self) -> str: class Address(StaticArray): def __init__(self) -> None: - super().__init__(AddressTypeSpec(), address_length) + super().__init__(AddressTypeSpec(), ADDRESS_LENGTH) def type_spec(self) -> AddressTypeSpec: return AddressTypeSpec() diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py index 345bb2b2e..e7267a7e8 100644 --- a/pyteal/ast/abi/address_test.py +++ b/pyteal/ast/abi/address_test.py @@ -1,5 +1,3 @@ -from .type_test import ContainerType - from ... import * options = CompileOptions(version=5) @@ -14,7 +12,7 @@ def test_AddressTypeSpec_is_dynamic(): def test_AddressTypeSpec_byte_length_static(): - assert (abi.AddressTypeSpec()).byte_length_static() == 32 + assert (abi.AddressTypeSpec()).byte_length_static() == abi.ADDRESS_LENGTH def test_AddressTypeSpec_new_instance(): @@ -47,7 +45,7 @@ def test_Address_decode(): from os import urandom value = abi.Address() - for value_to_set in [urandom(32) for x in range(10)]: + for value_to_set in [urandom(abi.ADDRESS_LENGTH) for x in range(10)]: expr = value.decode(Bytes(value_to_set)) assert expr.type_of() == TealType.none From 41ab8110c38b5556e410ce93bd1aa73b6c3745ae Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 20 Apr 2022 09:15:15 -0400 Subject: [PATCH 07/11] Update pyteal/ast/abi/address_test.py Co-authored-by: Zeph Grunschlag --- pyteal/ast/abi/address_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py index e7267a7e8..83353c13b 100644 --- a/pyteal/ast/abi/address_test.py +++ b/pyteal/ast/abi/address_test.py @@ -8,7 +8,7 @@ def test_AddressTypeSpec_str(): def test_AddressTypeSpec_is_dynamic(): - assert not (abi.AddressTypeSpec()).is_dynamic() + assert (abi.AddressTypeSpec()).is_dynamic() is False def test_AddressTypeSpec_byte_length_static(): From 1c22d14cec24704cc57cc16b0bcc3e889bf2815d Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 20 Apr 2022 09:19:32 -0400 Subject: [PATCH 08/11] cr fix --- pyteal/ast/abi/address_test.py | 6 +++--- pyteal/ast/abi/string_test.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py index 83353c13b..1227df77b 100644 --- a/pyteal/ast/abi/address_test.py +++ b/pyteal/ast/abi/address_test.py @@ -34,7 +34,7 @@ def test_Address_encode(): value = abi.Address() expr = value.encode() assert expr.type_of() == TealType.bytes - assert not expr.has_return() + assert expr.has_return() is False expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) actual, _ = expr.__teal__(options) @@ -49,7 +49,7 @@ def test_Address_decode(): expr = value.decode(Bytes(value_to_set)) assert expr.type_of() == TealType.none - assert not expr.has_return() + assert expr.has_return() is False expected = TealSimpleBlock( [ @@ -69,7 +69,7 @@ def test_Address_get(): value = abi.Address() expr = value.get() assert expr.type_of() == TealType.bytes - assert not expr.has_return() + assert expr.has_return() is False expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) actual, _ = expr.__teal__(options) diff --git a/pyteal/ast/abi/string_test.py b/pyteal/ast/abi/string_test.py index 45da165fc..856f48ddf 100644 --- a/pyteal/ast/abi/string_test.py +++ b/pyteal/ast/abi/string_test.py @@ -30,7 +30,7 @@ def test_String_encode(): value = abi.String() expr = value.encode() assert expr.type_of() == TealType.bytes - assert not expr.has_return() + assert expr.has_return() is False expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) actual, _ = expr.__teal__(options) @@ -46,7 +46,7 @@ def test_String_decode(): expr = value.decode(Bytes(value_to_set)) assert expr.type_of() == TealType.none - assert not expr.has_return() + assert expr.has_return() is False expected = TealSimpleBlock( [ @@ -66,7 +66,7 @@ def test_String_get(): value = abi.String() expr = value.get() assert expr.type_of() == TealType.bytes - assert not expr.has_return() + assert expr.has_return() is False expected = TealSimpleBlock( [TealOp(expr, Op.load, value.stored_value.slot), TealOp(None, Op.extract, 2, 0)] From 477a3043fd95b09f892cf6b795b1d469b966c1c8 Mon Sep 17 00:00:00 2001 From: michaeldiamant Date: Wed, 20 Apr 2022 20:55:05 -0400 Subject: [PATCH 09/11] Move to pyteal as pt in #278 --- pyteal/ast/abi/address_test.py | 31 +++++++++++++++------------ pyteal/ast/abi/string_test.py | 38 ++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/pyteal/ast/abi/address_test.py b/pyteal/ast/abi/address_test.py index 1227df77b..b6d5bde39 100644 --- a/pyteal/ast/abi/address_test.py +++ b/pyteal/ast/abi/address_test.py @@ -1,6 +1,7 @@ -from ... import * +import pyteal as pt +from pyteal import abi -options = CompileOptions(version=5) +options = pt.CompileOptions(version=5) def test_AddressTypeSpec_str(): @@ -33,10 +34,12 @@ def test_AddressTypeSpec_eq(): def test_Address_encode(): value = abi.Address() expr = value.encode() - assert expr.type_of() == TealType.bytes + assert expr.type_of() == pt.TealType.bytes assert expr.has_return() is False - expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) + expected = pt.TealSimpleBlock( + [pt.TealOp(expr, pt.Op.load, value.stored_value.slot)] + ) actual, _ = expr.__teal__(options) assert actual == expected @@ -46,31 +49,33 @@ def test_Address_decode(): value = abi.Address() for value_to_set in [urandom(abi.ADDRESS_LENGTH) for x in range(10)]: - expr = value.decode(Bytes(value_to_set)) + expr = value.decode(pt.Bytes(value_to_set)) - assert expr.type_of() == TealType.none + assert expr.type_of() == pt.TealType.none assert expr.has_return() is False - expected = TealSimpleBlock( + expected = pt.TealSimpleBlock( [ - TealOp(None, Op.byte, f"0x{value_to_set.hex()}"), - TealOp(None, Op.store, value.stored_value.slot), + pt.TealOp(None, pt.Op.byte, f"0x{value_to_set.hex()}"), + pt.TealOp(None, pt.Op.store, value.stored_value.slot), ] ) actual, _ = expr.__teal__(options) actual.addIncoming() - actual = TealBlock.NormalizeBlocks(actual) + actual = pt.TealBlock.NormalizeBlocks(actual) - with TealComponent.Context.ignoreExprEquality(): + with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected def test_Address_get(): value = abi.Address() expr = value.get() - assert expr.type_of() == TealType.bytes + assert expr.type_of() == pt.TealType.bytes assert expr.has_return() is False - expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) + expected = pt.TealSimpleBlock( + [pt.TealOp(expr, pt.Op.load, value.stored_value.slot)] + ) actual, _ = expr.__teal__(options) assert actual == expected diff --git a/pyteal/ast/abi/string_test.py b/pyteal/ast/abi/string_test.py index 856f48ddf..c722c0d7a 100644 --- a/pyteal/ast/abi/string_test.py +++ b/pyteal/ast/abi/string_test.py @@ -1,6 +1,7 @@ -from ... import * +import pyteal as pt +from pyteal import abi -options = CompileOptions(version=5) +options = pt.CompileOptions(version=5) def test_StringTypeSpec_str(): @@ -29,10 +30,12 @@ def test_StringTypeSpec_eq(): def test_String_encode(): value = abi.String() expr = value.encode() - assert expr.type_of() == TealType.bytes + assert expr.type_of() == pt.TealType.bytes assert expr.has_return() is False - expected = TealSimpleBlock([TealOp(expr, Op.load, value.stored_value.slot)]) + expected = pt.TealSimpleBlock( + [pt.TealOp(expr, pt.Op.load, value.stored_value.slot)] + ) actual, _ = expr.__teal__(options) assert actual == expected @@ -43,37 +46,40 @@ def test_String_decode(): value = abi.String() for value_to_set in [urandom(random.randint(0, 50)) for x in range(10)]: - expr = value.decode(Bytes(value_to_set)) + expr = value.decode(pt.Bytes(value_to_set)) - assert expr.type_of() == TealType.none + assert expr.type_of() == pt.TealType.none assert expr.has_return() is False - expected = TealSimpleBlock( + expected = pt.TealSimpleBlock( [ - TealOp(None, Op.byte, f"0x{value_to_set.hex()}"), - TealOp(None, Op.store, value.stored_value.slot), + pt.TealOp(None, pt.Op.byte, f"0x{value_to_set.hex()}"), + pt.TealOp(None, pt.Op.store, value.stored_value.slot), ] ) actual, _ = expr.__teal__(options) actual.addIncoming() - actual = TealBlock.NormalizeBlocks(actual) + actual = pt.TealBlock.NormalizeBlocks(actual) - with TealComponent.Context.ignoreExprEquality(): + with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected def test_String_get(): value = abi.String() expr = value.get() - assert expr.type_of() == TealType.bytes + assert expr.type_of() == pt.TealType.bytes assert expr.has_return() is False - expected = TealSimpleBlock( - [TealOp(expr, Op.load, value.stored_value.slot), TealOp(None, Op.extract, 2, 0)] + expected = pt.TealSimpleBlock( + [ + pt.TealOp(expr, pt.Op.load, value.stored_value.slot), + pt.TealOp(None, pt.Op.extract, 2, 0), + ] ) actual, _ = expr.__teal__(options) actual.addIncoming() - actual = TealBlock.NormalizeBlocks(actual) + actual = pt.TealBlock.NormalizeBlocks(actual) - with TealComponent.Context.ignoreExprEquality(): + with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected From 2085202b3c3e32e4bcde2c2f871aadd9dad3aee7 Mon Sep 17 00:00:00 2001 From: michaeldiamant Date: Wed, 20 Apr 2022 21:19:52 -0400 Subject: [PATCH 10/11] Merge absolute imports into feature/abi --- .flake8 | 7 ++ CONTRIBUTING.md | 62 ++++++++++++-- README.md | 2 +- pyteal/__init__.py | 21 +++-- pyteal/__init__.pyi | 21 +++-- pyteal/ast/__init__.py | 92 +++++++++++---------- pyteal/ast/acct.py | 8 +- pyteal/ast/addr.py | 8 +- pyteal/ast/app.py | 16 ++-- pyteal/ast/arg.py | 12 +-- pyteal/ast/array.py | 2 +- pyteal/ast/assert_.py | 8 +- pyteal/ast/asset.py | 8 +- pyteal/ast/binaryexpr.py | 10 +-- pyteal/ast/break_.py | 10 +-- pyteal/ast/bytes.py | 12 +-- pyteal/ast/cond.py | 10 +-- pyteal/ast/continue_.py | 10 +-- pyteal/ast/err.py | 8 +- pyteal/ast/expr.py | 46 +++++------ pyteal/ast/for_.py | 10 +-- pyteal/ast/gaid.py | 14 ++-- pyteal/ast/gitxn.py | 10 +-- pyteal/ast/gload.py | 14 ++-- pyteal/ast/global_.py | 10 +-- pyteal/ast/gtxn.py | 14 ++-- pyteal/ast/if_.py | 10 +-- pyteal/ast/int.py | 10 +-- pyteal/ast/itxn.py | 14 ++-- pyteal/ast/itxn_test.py | 2 +- pyteal/ast/leafexpr.py | 2 +- pyteal/ast/maybe.py | 8 +- pyteal/ast/methodsig.py | 10 +-- pyteal/ast/multi.py | 14 ++-- pyteal/ast/naryexpr.py | 10 +-- pyteal/ast/nonce.py | 12 +-- pyteal/ast/return_.py | 12 +-- pyteal/ast/scratch.py | 18 ++-- pyteal/ast/scratchvar.py | 8 +- pyteal/ast/seq.py | 10 +-- pyteal/ast/subroutine.py | 16 ++-- pyteal/ast/subroutine_test.py | 2 +- pyteal/ast/substring.py | 14 ++-- pyteal/ast/ternaryexpr.py | 10 +-- pyteal/ast/tmpl.py | 8 +- pyteal/ast/txn.py | 16 ++-- pyteal/ast/unaryexpr.py | 10 +-- pyteal/ast/while_.py | 10 +-- pyteal/ast/widemath.py | 10 +-- pyteal/compiler/__init__.py | 4 +- pyteal/compiler/compiler.py | 20 ++--- pyteal/compiler/constants.py | 6 +- pyteal/compiler/constants_test.py | 2 +- pyteal/compiler/flatten.py | 6 +- pyteal/compiler/flatten_test.py | 2 +- pyteal/compiler/optimizer/__init__.py | 5 +- pyteal/compiler/optimizer/optimizer.py | 6 +- pyteal/compiler/optimizer/optimizer_test.py | 2 +- pyteal/compiler/scratchslots.py | 8 +- pyteal/compiler/scratchslots_test.py | 5 +- pyteal/compiler/sort.py | 4 +- pyteal/compiler/sort_test.py | 2 +- pyteal/compiler/subroutines.py | 8 +- pyteal/compiler/subroutines_test.py | 2 +- pyteal/errors.py | 2 +- pyteal/ir/__init__.py | 16 ++-- pyteal/ir/tealblock.py | 13 ++- pyteal/ir/tealcomponent.py | 2 +- pyteal/ir/tealconditionalblock.py | 4 +- pyteal/ir/teallabel.py | 6 +- pyteal/ir/tealop.py | 18 ++-- pyteal/ir/tealsimpleblock.py | 4 +- pyteal/types.py | 2 +- pyteal/types_test.py | 2 +- pyteal/util.py | 2 +- setup.py | 1 + 76 files changed, 456 insertions(+), 379 deletions(-) diff --git a/.flake8 b/.flake8 index 07c9aaa51..9416fd23a 100644 --- a/.flake8 +++ b/.flake8 @@ -24,4 +24,11 @@ per-file-ignores = pyteal/__init__.py: F401, F403 pyteal/ir/ops.py: E221 tests/module_test.py: F401, F403 + tests/*.py: I252 + # Temporarily ignore until merge completes + pyteal/ast/abi/*.py: I252 + # End temporarty ignore + +# from flake8-tidy-imports +ban-relative-imports = true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ebd603e0..e9ed1daa2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,29 +2,27 @@ If you are interested in contributing to the project, we welcome and thank you. We want to make the best decentralized and effective blockchain platform available and we appreciate your willingness to help us. - - -# Filing Issues +## Filing Issues Did you discover a bug? Do you have a feature request? Filing issues is an easy way anyone can contribute and helps us improve PyTeal. We use GitHub Issues to track all known bugs and feature requests. -Before logging an issue be sure to check current issues, check the [Developer Frequently Asked Questions](https://developer.algorand.org/docs/developer-faq) and [GitHub issues][issues_url] to see if your issue is described there. +Before logging an issue be sure to check current issues, check the [open GitHub issues][issues_url] to see if your issue is described there. If you’d like to contribute to any of the repositories, please file a [GitHub issue][issues_url] using the issues menu item. Make sure to specify whether you are describing a bug or a new enhancement using the **Bug report** or **Feature request** button. See the GitHub help guide for more information on [filing an issue](https://help.github.com/en/articles/creating-an-issue). -# Contribution Model +## Contribution Model -For each of our repositories we use the same model for contributing code. Developers wanting to contribute must create pull requests. This process is described in the GitHub [Creating a pull request from a fork](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork) documentation. Each pull request should be initiated against the master branch in the Algorand repository. After a pull request is submitted the core development team will review the submission and communicate with the developer using the comments sections of the PR. After the submission is reviewed and approved, it will be merged into the master branch of the source. These changes will be merged to our release branch on the next viable release date. +For each of our repositories we use the same model for contributing code. Developers wanting to contribute must create pull requests. This process is described in the GitHub [Creating a pull request from a fork](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork) documentation. Each pull request should be initiated against the master branch in the Algorand repository. After a pull request is submitted the core development team will review the submission and communicate with the developer using the comments sections of the PR. After the submission is reviewed and approved, it will be merged into the master branch of the source. These changes will be merged to our release branch on the next viable release date. -# Code Guidelines +## Code Guidelines We make a best-effort attempt to adhere to [PEP 8 - Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/). Keep the following context in mind: * Our default stance is to run linter checks during the build process. * Notable exception: [naming conventions](https://peps.python.org/pep-0008/#naming-conventions). -## Naming Convention Guidelines +### Naming Convention Guidelines Since PyTeal aims for backwards compatibility, it's _not_ straightforward to change naming conventions in public APIs. Consequently, the repo contains some deviations from PEP 8 naming conventions. In order to retain a consistent style, we prefer to continue deviating from PEP 8 naming conventions in the following cases. We try to balance minimizing exceptions against providing a consistent style for existing software. @@ -32,3 +30,51 @@ In order to retain a consistent style, we prefer to continue deviating from PEP * Factory methods - Define following [class name](https://peps.python.org/pep-0008/#class-names) conventions. Example: https://github.com/algorand/pyteal/blob/7c953f600113abcb9a31df68165b61a2c897f591/pyteal/ast/ternaryexpr.py#L63 Since it's challenging to enforce these exceptions with a linter, we rely on PR creators and reviewers to make a best-effort attempt to enforce agreed upon naming conventions. + +### Module Guidelines + +Every directory containing source code should be a Python module, meaning it should have an `__init__.py` file. This `__init__.py` file is responsible for exporting all public objects (i.e. classes, functions, and constants) for use outside of that module. + +Modules may be created inside of other modules, in which case the deeper module is called a submodule or child module, and the module that contains it is called the parent module. For example, `pyteal` is the parent module to `pyteal.ast`. + +A sibling module is defined as a different child module of the parent module. For example, `pyteal.ast` and `pyteal.ir` are sibling modules. + +### Import Guidelines + +#### In Runtime Code + +When a runtime file in this codebase needs to import another module/file in this codebase, you should import the absolute path of the module/file, not the relative one, using the `from X import Y` method. + +With regard to modules, there are two ways to import an object from this codebase: + +* When importing an object from the same module or a parent module, you should import the full path of the source file that defines the object. For example: + * (Import from same module): If `pyteal/ast/seq.py` needs to import `Expr` defined in `pyteal/ast/expr.py`, it should use `from pyteal.ast.expr import Expr`. **DO NOT** use `from pyteal.ast import Expr` or `from pyteal import Expr`, as this will cause an unnecessary circular dependency. + * (Import from parent module): If `pyteal/ast/seq.py` needs to import `TealType` defined in `pyteal/types.py`, it should use `from pyteal.types import TealType`. **DO NOT** use `from pyteal import TealType`, as this will cause an unnecessary circular dependency. + +* When importing an object from a child module or sibling module, you should import the entire module folder and access the desired object from there. Do not directly import the file that defines the object. For example: + * (Import from child module): If `pyteal/compiler/compiler.py` needs to import `OptimizeOptions` from `pyteal/compiler/optimizer/optimizer.py`, it should use `from pyteal.compiler.optimizer import OptimizeOptions`. **DO NOT** use `from pyteal.compiler.optimizer.optimizer import OptimizeOptions`, as this will bypass the file `pyteal/compiler/optimizer/__init__.py`, which carefully defines the exports for the `pyteal.compiler.optimizer` module. + * (Import from sibling module): If `pyteal/compiler/compiler.py` needs to import `Expr` defined in `pyteal/ast/expr.py`, it should use `from pyteal.ast import Expr`. **DO NOT** use `from pyteal import Expr`, as this will cause an unnecessary circular dependency, nor `from pyteal.ast.expr import Expr`, as this will bypass the file `pyteal/ast/__init__.py`, which carefully defines the + exports for the `pyteal.ast` module. + +When this approach is followed properly, circular dependencies can happen in two ways: +1. **Intra-module circular dependencies**, e.g. `m1/a.py` imports `m1/b.py` which imports `m1/a.py`. + When this happens, normally one of the files only needs to import the other to implement something, + so the import statements can be moved from the top of the file to the body of the function that + needs them. This breaks the import cycle. + +2. **Inter-module circular dependencies**, e.g. `m1/a.py` imports module `m1/m2/__init__.py` which + imports `m1/m2/x.py` which imports `m1/a.py`. To avoid this, make sure that any objects/files in + `m1` that need to be exposed to deeper modules do not rely on any objects from that deeper module. + If that isn’t possible, then perhaps `m1/a.py` belongs in the `m1/m2/` module. + +#### In Test Code + +Test code is typically any file that ends with `_test.py` or is in the top-level `tests` folder. In +order to have a strong guarantee that we are testing in a similar environment to consumers of this +library, test code is encouraged to import _only_ the top-level PyTeal module, either with +`from pyteal import X, Y, Z` or `import pyteal as pt`. + +This way we can be sure all objects that should be publicly exported are in fact accessible from the top-level module. + +The only exception to this should be if the tests are for a non-exported object, in which case it is +necessary to import the object according to the runtime rules in the previous section. diff --git a/README.md b/README.md index 8b5ac2f0f..61db520c4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # PyTeal: Algorand Smart Contracts in Python -[![Build Status](https://travis-ci.com/algorand/pyteal.svg?branch=master)](https://travis-ci.com/algorand/pyteal) +[![Build Status](https://github.com/algorand/pyteal/actions/workflows/build.yml/badge.svg)](https://github.com/algorand/pyteal/actions) [![PyPI version](https://badge.fury.io/py/pyteal.svg)](https://badge.fury.io/py/pyteal) [![Documentation Status](https://readthedocs.org/projects/pyteal/badge/?version=latest)](https://pyteal.readthedocs.io/en/latest/?badge=latest) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) diff --git a/pyteal/__init__.py b/pyteal/__init__.py index 99d6e4828..ae30dd312 100644 --- a/pyteal/__init__.py +++ b/pyteal/__init__.py @@ -1,8 +1,8 @@ -from .ast import * -from .ast import __all__ as ast_all -from .ir import * -from .ir import __all__ as ir_all -from .compiler import ( +from pyteal.ast import * +from pyteal.ast import __all__ as ast_all +from pyteal.ir import * +from pyteal.ir import __all__ as ir_all +from pyteal.compiler import ( MAX_TEAL_VERSION, MIN_TEAL_VERSION, DEFAULT_TEAL_VERSION, @@ -10,9 +10,14 @@ compileTeal, OptimizeOptions, ) -from .types import TealType -from .errors import TealInternalError, TealTypeError, TealInputError, TealCompileError -from .config import MAX_GROUP_SIZE, NUM_SLOTS +from pyteal.types import TealType +from pyteal.errors import ( + TealInternalError, + TealTypeError, + TealInputError, + TealCompileError, +) +from pyteal.config import MAX_GROUP_SIZE, NUM_SLOTS # begin __all__ __all__ = ( diff --git a/pyteal/__init__.pyi b/pyteal/__init__.pyi index 772080ae2..851c0dd3b 100644 --- a/pyteal/__init__.pyi +++ b/pyteal/__init__.pyi @@ -1,11 +1,11 @@ ## File generated from scripts/generate_init.py. ## DO NOT EDIT DIRECTLY -from .ast import * -from .ast import __all__ as ast_all -from .ir import * -from .ir import __all__ as ir_all -from .compiler import ( +from pyteal.ast import * +from pyteal.ast import __all__ as ast_all +from pyteal.ir import * +from pyteal.ir import __all__ as ir_all +from pyteal.compiler import ( MAX_TEAL_VERSION, MIN_TEAL_VERSION, DEFAULT_TEAL_VERSION, @@ -13,9 +13,14 @@ from .compiler import ( compileTeal, OptimizeOptions, ) -from .types import TealType -from .errors import TealInternalError, TealTypeError, TealInputError, TealCompileError -from .config import MAX_GROUP_SIZE, NUM_SLOTS +from pyteal.types import TealType +from pyteal.errors import ( + TealInternalError, + TealTypeError, + TealInputError, + TealCompileError, +) +from pyteal.config import MAX_GROUP_SIZE, NUM_SLOTS __all__ = [ "AccountParam", diff --git a/pyteal/ast/__init__.py b/pyteal/ast/__init__.py index 95ca290c6..7d951442e 100644 --- a/pyteal/ast/__init__.py +++ b/pyteal/ast/__init__.py @@ -1,35 +1,43 @@ # abstract types -from .expr import Expr +from pyteal.ast.expr import Expr # basic types -from .leafexpr import LeafExpr -from .addr import Addr -from .bytes import Bytes -from .int import Int, EnumInt -from .methodsig import MethodSignature +from pyteal.ast.leafexpr import LeafExpr +from pyteal.ast.addr import Addr +from pyteal.ast.bytes import Bytes +from pyteal.ast.int import Int, EnumInt +from pyteal.ast.methodsig import MethodSignature # properties -from .arg import Arg -from .txn import TxnType, TxnField, TxnExpr, TxnaExpr, TxnArray, TxnObject, Txn -from .gtxn import GtxnExpr, GtxnaExpr, TxnGroup, Gtxn -from .gaid import GeneratedID -from .gitxn import Gitxn, GitxnExpr, GitxnaExpr, InnerTxnGroup -from .gload import ImportScratchValue -from .global_ import Global, GlobalField -from .app import App, AppField, OnComplete, AppParam -from .asset import AssetHolding, AssetParam -from .acct import AccountParam +from pyteal.ast.arg import Arg +from pyteal.ast.txn import ( + TxnType, + TxnField, + TxnExpr, + TxnaExpr, + TxnArray, + TxnObject, + Txn, +) +from pyteal.ast.gtxn import GtxnExpr, GtxnaExpr, TxnGroup, Gtxn +from pyteal.ast.gaid import GeneratedID +from pyteal.ast.gitxn import Gitxn, GitxnExpr, GitxnaExpr, InnerTxnGroup +from pyteal.ast.gload import ImportScratchValue +from pyteal.ast.global_ import Global, GlobalField +from pyteal.ast.app import App, AppField, OnComplete, AppParam +from pyteal.ast.asset import AssetHolding, AssetParam +from pyteal.ast.acct import AccountParam # inner txns -from .itxn import InnerTxnBuilder, InnerTxn, InnerTxnAction +from pyteal.ast.itxn import InnerTxnBuilder, InnerTxn, InnerTxnAction # meta -from .array import Array -from .tmpl import Tmpl -from .nonce import Nonce +from pyteal.ast.array import Array +from pyteal.ast.tmpl import Tmpl +from pyteal.ast.nonce import Nonce # unary ops -from .unaryexpr import ( +from pyteal.ast.unaryexpr import ( UnaryExpr, Btoi, Itob, @@ -51,7 +59,7 @@ ) # binary ops -from .binaryexpr import ( +from pyteal.ast.binaryexpr import ( BinaryExpr, Minus, Div, @@ -90,47 +98,47 @@ ) # ternary ops -from .ternaryexpr import Divw, Ed25519Verify, SetBit, SetByte -from .substring import Substring, Extract, Suffix +from pyteal.ast.ternaryexpr import Divw, Ed25519Verify, SetBit, SetByte +from pyteal.ast.substring import Substring, Extract, Suffix # more ops -from .naryexpr import NaryExpr, Add, Mul, And, Or, Concat -from .widemath import WideRatio +from pyteal.ast.naryexpr import NaryExpr, Add, Mul, And, Or, Concat +from pyteal.ast.widemath import WideRatio # control flow -from .if_ import If -from .cond import Cond -from .seq import Seq -from .assert_ import Assert -from .err import Err -from .return_ import Return, Approve, Reject -from .subroutine import ( +from pyteal.ast.if_ import If +from pyteal.ast.cond import Cond +from pyteal.ast.seq import Seq +from pyteal.ast.assert_ import Assert +from pyteal.ast.err import Err +from pyteal.ast.return_ import Return, Approve, Reject +from pyteal.ast.subroutine import ( Subroutine, SubroutineDefinition, SubroutineDeclaration, SubroutineCall, SubroutineFnWrapper, ) -from .while_ import While -from .for_ import For -from .break_ import Break -from .continue_ import Continue +from pyteal.ast.while_ import While +from pyteal.ast.for_ import For +from pyteal.ast.break_ import Break +from pyteal.ast.continue_ import Continue # misc -from .scratch import ( +from pyteal.ast.scratch import ( ScratchIndex, ScratchLoad, ScratchSlot, ScratchStackStore, ScratchStore, ) -from .scratchvar import DynamicScratchVar, ScratchVar -from .maybe import MaybeValue -from .multi import MultiValue +from pyteal.ast.scratchvar import DynamicScratchVar, ScratchVar +from pyteal.ast.maybe import MaybeValue +from pyteal.ast.multi import MultiValue # abi -from . import abi +from pyteal.ast import abi __all__ = [ "Expr", diff --git a/pyteal/ast/acct.py b/pyteal/ast/acct.py index ae8475eae..c08f2760b 100644 --- a/pyteal/ast/acct.py +++ b/pyteal/ast/acct.py @@ -1,7 +1,7 @@ -from ..types import TealType, require_type -from ..ir import Op -from .expr import Expr -from .maybe import MaybeValue +from pyteal.types import TealType, require_type +from pyteal.ir import Op +from pyteal.ast.expr import Expr +from pyteal.ast.maybe import MaybeValue class AccountParam: diff --git a/pyteal/ast/addr.py b/pyteal/ast/addr.py index 4c6b6bbe1..fb6687777 100644 --- a/pyteal/ast/addr.py +++ b/pyteal/ast/addr.py @@ -1,11 +1,11 @@ from typing import TYPE_CHECKING -from ..types import TealType, valid_address -from ..ir import TealOp, Op, TealBlock -from .leafexpr import LeafExpr +from pyteal.types import TealType, valid_address +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Addr(LeafExpr): diff --git a/pyteal/ast/app.py b/pyteal/ast/app.py index 23e265094..adf18f6a7 100644 --- a/pyteal/ast/app.py +++ b/pyteal/ast/app.py @@ -1,16 +1,16 @@ from typing import TYPE_CHECKING from enum import Enum -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealBlock -from .leafexpr import LeafExpr -from .expr import Expr -from .maybe import MaybeValue -from .int import EnumInt -from .global_ import Global +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.leafexpr import LeafExpr +from pyteal.ast.expr import Expr +from pyteal.ast.maybe import MaybeValue +from pyteal.ast.int import EnumInt +from pyteal.ast.global_ import Global if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class OnComplete: diff --git a/pyteal/ast/arg.py b/pyteal/ast/arg.py index be0d3dd05..4c5697eda 100644 --- a/pyteal/ast/arg.py +++ b/pyteal/ast/arg.py @@ -1,13 +1,13 @@ from typing import Union, cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealBlock -from ..errors import TealInputError, verifyTealVersion -from .expr import Expr -from .leafexpr import LeafExpr +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError, verifyTealVersion +from pyteal.ast.expr import Expr +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Arg(LeafExpr): diff --git a/pyteal/ast/array.py b/pyteal/ast/array.py index 5a1fb9bdc..3a9c4c61a 100644 --- a/pyteal/ast/array.py +++ b/pyteal/ast/array.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod -from .expr import Expr +from pyteal.ast.expr import Expr class Array(ABC): diff --git a/pyteal/ast/assert_.py b/pyteal/ast/assert_.py index 0d9b65b17..6b448825b 100644 --- a/pyteal/ast/assert_.py +++ b/pyteal/ast/assert_.py @@ -1,11 +1,11 @@ from typing import TYPE_CHECKING -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealBlock, TealSimpleBlock, TealConditionalBlock -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealBlock, TealSimpleBlock, TealConditionalBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Assert(Expr): diff --git a/pyteal/ast/asset.py b/pyteal/ast/asset.py index 2ad65c20e..a39879be2 100644 --- a/pyteal/ast/asset.py +++ b/pyteal/ast/asset.py @@ -1,7 +1,7 @@ -from ..types import TealType, require_type -from ..ir import Op -from .expr import Expr -from .maybe import MaybeValue +from pyteal.types import TealType, require_type +from pyteal.ir import Op +from pyteal.ast.expr import Expr +from pyteal.ast.maybe import MaybeValue class AssetHolding: diff --git a/pyteal/ast/binaryexpr.py b/pyteal/ast/binaryexpr.py index a2020c843..2243d901b 100644 --- a/pyteal/ast/binaryexpr.py +++ b/pyteal/ast/binaryexpr.py @@ -1,12 +1,12 @@ from typing import Union, Tuple, cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..errors import verifyTealVersion -from ..ir import TealOp, Op, TealBlock -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.errors import verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class BinaryExpr(Expr): diff --git a/pyteal/ast/break_.py b/pyteal/ast/break_.py index 827c77bdd..80b2e4590 100644 --- a/pyteal/ast/break_.py +++ b/pyteal/ast/break_.py @@ -1,13 +1,13 @@ from typing import TYPE_CHECKING -from ..types import TealType -from ..errors import TealCompileError -from .expr import Expr -from ..ir import TealSimpleBlock +from pyteal.types import TealType +from pyteal.errors import TealCompileError +from pyteal.ast.expr import Expr +from pyteal.ir import TealSimpleBlock if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Break(Expr): diff --git a/pyteal/ast/bytes.py b/pyteal/ast/bytes.py index 1bb58b4dc..e88163611 100644 --- a/pyteal/ast/bytes.py +++ b/pyteal/ast/bytes.py @@ -1,13 +1,13 @@ from typing import Union, cast, overload, TYPE_CHECKING -from ..types import TealType, valid_base16, valid_base32, valid_base64 -from ..util import escapeStr -from ..ir import TealOp, Op, TealBlock -from ..errors import TealInputError -from .leafexpr import LeafExpr +from pyteal.types import TealType, valid_base16, valid_base32, valid_base64 +from pyteal.util import escapeStr +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Bytes(LeafExpr): diff --git a/pyteal/ast/cond.py b/pyteal/ast/cond.py index 60cb097bf..8dbe92cab 100644 --- a/pyteal/ast/cond.py +++ b/pyteal/ast/cond.py @@ -1,12 +1,12 @@ from typing import List, cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealSimpleBlock, TealConditionalBlock -from ..errors import TealInputError -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealSimpleBlock, TealConditionalBlock +from pyteal.errors import TealInputError +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Cond(Expr): diff --git a/pyteal/ast/continue_.py b/pyteal/ast/continue_.py index ddfef43bf..a134925bd 100644 --- a/pyteal/ast/continue_.py +++ b/pyteal/ast/continue_.py @@ -1,13 +1,13 @@ from typing import TYPE_CHECKING -from ..types import TealType -from ..errors import TealCompileError -from .expr import Expr -from ..ir import TealSimpleBlock +from pyteal.types import TealType +from pyteal.errors import TealCompileError +from pyteal.ast.expr import Expr +from pyteal.ir import TealSimpleBlock if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Continue(Expr): diff --git a/pyteal/ast/err.py b/pyteal/ast/err.py index aea616863..1b4df9bb8 100644 --- a/pyteal/ast/err.py +++ b/pyteal/ast/err.py @@ -1,11 +1,11 @@ from typing import TYPE_CHECKING -from ..types import TealType -from ..ir import TealOp, Op, TealBlock -from .expr import Expr +from pyteal.types import TealType +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Err(Expr): diff --git a/pyteal/ast/expr.py b/pyteal/ast/expr.py index 43a8da06d..c2de1ca32 100644 --- a/pyteal/ast/expr.py +++ b/pyteal/ast/expr.py @@ -1,11 +1,11 @@ from abc import ABC, abstractmethod from typing import Tuple, List, TYPE_CHECKING -from ..types import TealType -from ..ir import TealBlock, TealSimpleBlock +from pyteal.types import TealType +from pyteal.ir import TealBlock, TealSimpleBlock if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Expr(ABC): @@ -40,92 +40,92 @@ def __teal__(self, options: "CompileOptions") -> Tuple[TealBlock, TealSimpleBloc pass def __lt__(self, other): - from .binaryexpr import Lt + from pyteal.ast.binaryexpr import Lt return Lt(self, other) def __gt__(self, other): - from .binaryexpr import Gt + from pyteal.ast.binaryexpr import Gt return Gt(self, other) def __le__(self, other): - from .binaryexpr import Le + from pyteal.ast.binaryexpr import Le return Le(self, other) def __ge__(self, other): - from .binaryexpr import Ge + from pyteal.ast.binaryexpr import Ge return Ge(self, other) def __eq__(self, other): - from .binaryexpr import Eq + from pyteal.ast.binaryexpr import Eq return Eq(self, other) def __ne__(self, other): - from .binaryexpr import Neq + from pyteal.ast.binaryexpr import Neq return Neq(self, other) def __add__(self, other): - from .naryexpr import Add + from pyteal.ast.naryexpr import Add return Add(self, other) def __sub__(self, other): - from .binaryexpr import Minus + from pyteal.ast.binaryexpr import Minus return Minus(self, other) def __mul__(self, other): - from .naryexpr import Mul + from pyteal.ast.naryexpr import Mul return Mul(self, other) def __truediv__(self, other): - from .binaryexpr import Div + from pyteal.ast.binaryexpr import Div return Div(self, other) def __mod__(self, other): - from .binaryexpr import Mod + from pyteal.ast.binaryexpr import Mod return Mod(self, other) def __pow__(self, other): - from .binaryexpr import Exp + from pyteal.ast.binaryexpr import Exp return Exp(self, other) def __invert__(self): - from .unaryexpr import BitwiseNot + from pyteal.ast.unaryexpr import BitwiseNot return BitwiseNot(self) def __and__(self, other): - from .binaryexpr import BitwiseAnd + from pyteal.ast.binaryexpr import BitwiseAnd return BitwiseAnd(self, other) def __or__(self, other): - from .binaryexpr import BitwiseOr + from pyteal.ast.binaryexpr import BitwiseOr return BitwiseOr(self, other) def __xor__(self, other): - from .binaryexpr import BitwiseXor + from pyteal.ast.binaryexpr import BitwiseXor return BitwiseXor(self, other) def __lshift__(self, other): - from .binaryexpr import ShiftLeft + from pyteal.ast.binaryexpr import ShiftLeft return ShiftLeft(self, other) def __rshift__(self, other): - from .binaryexpr import ShiftRight + from pyteal.ast.binaryexpr import ShiftRight return ShiftRight(self, other) @@ -136,7 +136,7 @@ def And(self, other: "Expr") -> "Expr": This is the same as using :func:`And()` with two arguments. """ - from .naryexpr import And + from pyteal.ast.naryexpr import And return And(self, other) @@ -147,7 +147,7 @@ def Or(self, other: "Expr") -> "Expr": This is the same as using :func:`Or()` with two arguments. """ - from .naryexpr import Or + from pyteal.ast.naryexpr import Or return Or(self, other) diff --git a/pyteal/ast/for_.py b/pyteal/ast/for_.py index d7897253f..d8a0cca27 100644 --- a/pyteal/ast/for_.py +++ b/pyteal/ast/for_.py @@ -1,12 +1,12 @@ from typing import TYPE_CHECKING, Optional -from ..types import TealType, require_type -from ..ir import TealSimpleBlock, TealConditionalBlock -from ..errors import TealCompileError -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.ir import TealSimpleBlock, TealConditionalBlock +from pyteal.errors import TealCompileError +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class For(Expr): diff --git a/pyteal/ast/gaid.py b/pyteal/ast/gaid.py index 7b95f1617..d9faa6128 100644 --- a/pyteal/ast/gaid.py +++ b/pyteal/ast/gaid.py @@ -1,14 +1,14 @@ from typing import cast, Union, TYPE_CHECKING -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealBlock -from ..errors import TealInputError, verifyTealVersion -from ..config import MAX_GROUP_SIZE -from .expr import Expr -from .leafexpr import LeafExpr +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError, verifyTealVersion +from pyteal.config import MAX_GROUP_SIZE +from pyteal.ast.expr import Expr +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class GeneratedID(LeafExpr): diff --git a/pyteal/ast/gitxn.py b/pyteal/ast/gitxn.py index bbfa687a0..486120e07 100644 --- a/pyteal/ast/gitxn.py +++ b/pyteal/ast/gitxn.py @@ -2,13 +2,13 @@ from pyteal.config import MAX_GROUP_SIZE -from ..errors import TealInputError, verifyFieldVersion, verifyTealVersion -from ..ir import TealOp, Op, TealBlock -from .expr import Expr -from .txn import TxnExpr, TxnField, TxnObject, TxnaExpr +from pyteal.errors import TealInputError, verifyFieldVersion, verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr +from pyteal.ast.txn import TxnExpr, TxnField, TxnObject, TxnaExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class GitxnExpr(TxnExpr): diff --git a/pyteal/ast/gload.py b/pyteal/ast/gload.py index d0963dc27..0c4b86c55 100644 --- a/pyteal/ast/gload.py +++ b/pyteal/ast/gload.py @@ -1,14 +1,14 @@ from typing import cast, Union, TYPE_CHECKING -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealBlock -from ..errors import TealInputError, verifyTealVersion -from ..config import MAX_GROUP_SIZE, NUM_SLOTS -from .expr import Expr -from .leafexpr import LeafExpr +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError, verifyTealVersion +from pyteal.config import MAX_GROUP_SIZE, NUM_SLOTS +from pyteal.ast.expr import Expr +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class ImportScratchValue(LeafExpr): diff --git a/pyteal/ast/global_.py b/pyteal/ast/global_.py index 070dfdca3..b6b9c339f 100644 --- a/pyteal/ast/global_.py +++ b/pyteal/ast/global_.py @@ -1,13 +1,13 @@ from typing import TYPE_CHECKING from enum import Enum -from ..types import TealType -from ..errors import verifyFieldVersion -from ..ir import TealOp, Op, TealBlock -from .leafexpr import LeafExpr +from pyteal.types import TealType +from pyteal.errors import verifyFieldVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class GlobalField(Enum): diff --git a/pyteal/ast/gtxn.py b/pyteal/ast/gtxn.py index b12f8f9d5..640f0605d 100644 --- a/pyteal/ast/gtxn.py +++ b/pyteal/ast/gtxn.py @@ -1,14 +1,14 @@ from typing import Union, cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..ir import TealOp, Op, TealBlock -from ..errors import TealInputError, verifyFieldVersion, verifyTealVersion -from ..config import MAX_GROUP_SIZE -from .expr import Expr -from .txn import TxnField, TxnExpr, TxnaExpr, TxnObject +from pyteal.types import TealType, require_type +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError, verifyFieldVersion, verifyTealVersion +from pyteal.config import MAX_GROUP_SIZE +from pyteal.ast.expr import Expr +from pyteal.ast.txn import TxnField, TxnExpr, TxnaExpr, TxnObject if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions def validate_txn_index_or_throw(txnIndex: Union[int, Expr]): diff --git a/pyteal/ast/if_.py b/pyteal/ast/if_.py index 389e17de5..605eb89e5 100644 --- a/pyteal/ast/if_.py +++ b/pyteal/ast/if_.py @@ -1,12 +1,12 @@ from typing import TYPE_CHECKING -from ..errors import TealCompileError, TealInputError -from ..types import TealType, require_type -from ..ir import TealSimpleBlock, TealConditionalBlock -from .expr import Expr +from pyteal.errors import TealCompileError, TealInputError +from pyteal.types import TealType, require_type +from pyteal.ir import TealSimpleBlock, TealConditionalBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class If(Expr): diff --git a/pyteal/ast/int.py b/pyteal/ast/int.py index 6a590f3b5..26ef8cff5 100644 --- a/pyteal/ast/int.py +++ b/pyteal/ast/int.py @@ -1,12 +1,12 @@ from typing import TYPE_CHECKING -from ..types import TealType -from ..ir import TealOp, Op, TealBlock -from ..errors import TealInputError -from .leafexpr import LeafExpr +from pyteal.types import TealType +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Int(LeafExpr): diff --git a/pyteal/ast/itxn.py b/pyteal/ast/itxn.py index ff857c808..af7704198 100644 --- a/pyteal/ast/itxn.py +++ b/pyteal/ast/itxn.py @@ -1,15 +1,15 @@ from enum import Enum from typing import Dict, TYPE_CHECKING, List, Union, cast -from ..types import TealType, require_type -from ..errors import TealInputError, verifyTealVersion -from ..ir import TealOp, Op, TealBlock -from .expr import Expr -from .txn import TxnField, TxnExprBuilder, TxnaExprBuilder, TxnObject -from .seq import Seq +from pyteal.types import TealType, require_type +from pyteal.errors import TealInputError, verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr +from pyteal.ast.txn import TxnField, TxnExprBuilder, TxnaExprBuilder, TxnObject +from pyteal.ast.seq import Seq if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class InnerTxnAction(Enum): diff --git a/pyteal/ast/itxn_test.py b/pyteal/ast/itxn_test.py index 53b65d2d4..af9c3a79c 100644 --- a/pyteal/ast/itxn_test.py +++ b/pyteal/ast/itxn_test.py @@ -1,7 +1,7 @@ import pytest import pyteal as pt -from ..types import types_match +from pyteal.types import types_match teal4Options = pt.CompileOptions(version=4) teal5Options = pt.CompileOptions(version=5) diff --git a/pyteal/ast/leafexpr.py b/pyteal/ast/leafexpr.py index 6a39b39d4..e03905060 100644 --- a/pyteal/ast/leafexpr.py +++ b/pyteal/ast/leafexpr.py @@ -1,4 +1,4 @@ -from .expr import Expr +from pyteal.ast.expr import Expr class LeafExpr(Expr): diff --git a/pyteal/ast/maybe.py b/pyteal/ast/maybe.py index 9ce9e2521..43846384d 100644 --- a/pyteal/ast/maybe.py +++ b/pyteal/ast/maybe.py @@ -2,10 +2,10 @@ from pyteal.ast.multi import MultiValue -from ..types import TealType -from ..ir import Op -from .expr import Expr -from .scratch import ScratchLoad, ScratchSlot +from pyteal.types import TealType +from pyteal.ir import Op +from pyteal.ast.expr import Expr +from pyteal.ast.scratch import ScratchLoad, ScratchSlot class MaybeValue(MultiValue): diff --git a/pyteal/ast/methodsig.py b/pyteal/ast/methodsig.py index b10e03b49..9417890de 100644 --- a/pyteal/ast/methodsig.py +++ b/pyteal/ast/methodsig.py @@ -1,13 +1,13 @@ from typing import TYPE_CHECKING -from ..errors import TealInputError -from ..types import TealType -from ..ir import TealOp, Op, TealBlock +from pyteal.errors import TealInputError +from pyteal.types import TealType +from pyteal.ir import TealOp, Op, TealBlock -from .leafexpr import LeafExpr +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class MethodSignature(LeafExpr): diff --git a/pyteal/ast/multi.py b/pyteal/ast/multi.py index de8aef39d..63a4dec11 100644 --- a/pyteal/ast/multi.py +++ b/pyteal/ast/multi.py @@ -1,14 +1,14 @@ from typing import Callable, List, Union, TYPE_CHECKING -from ..types import TealType -from ..ir import TealOp, Op, TealBlock -from .expr import Expr -from .leafexpr import LeafExpr -from .scratch import ScratchSlot -from .seq import Seq +from pyteal.types import TealType +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr +from pyteal.ast.leafexpr import LeafExpr +from pyteal.ast.scratch import ScratchSlot +from pyteal.ast.seq import Seq if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class MultiValue(LeafExpr): diff --git a/pyteal/ast/naryexpr.py b/pyteal/ast/naryexpr.py index cd7d01452..f0aa564e8 100644 --- a/pyteal/ast/naryexpr.py +++ b/pyteal/ast/naryexpr.py @@ -1,12 +1,12 @@ from typing import Sequence, cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..errors import TealInputError -from ..ir import TealOp, Op, TealSimpleBlock -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.errors import TealInputError +from pyteal.ir import TealOp, Op, TealSimpleBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class NaryExpr(Expr): diff --git a/pyteal/ast/nonce.py b/pyteal/ast/nonce.py index ff61f5b30..ce007f322 100644 --- a/pyteal/ast/nonce.py +++ b/pyteal/ast/nonce.py @@ -1,13 +1,13 @@ from typing import TYPE_CHECKING -from ..errors import TealInputError -from .expr import Expr -from .seq import Seq -from .bytes import Bytes -from .unaryexpr import Pop +from pyteal.errors import TealInputError +from pyteal.ast.expr import Expr +from pyteal.ast.seq import Seq +from pyteal.ast.bytes import Bytes +from pyteal.ast.unaryexpr import Pop if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Nonce(Expr): diff --git a/pyteal/ast/return_.py b/pyteal/ast/return_.py index 309134219..3d2b809d1 100644 --- a/pyteal/ast/return_.py +++ b/pyteal/ast/return_.py @@ -1,13 +1,13 @@ from typing import TYPE_CHECKING -from ..types import TealType, require_type, types_match -from ..errors import verifyTealVersion, TealCompileError -from ..ir import TealOp, Op, TealBlock -from .expr import Expr -from .int import Int +from pyteal.types import TealType, require_type, types_match +from pyteal.errors import verifyTealVersion, TealCompileError +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr +from pyteal.ast.int import Int if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Return(Expr): diff --git a/pyteal/ast/scratch.py b/pyteal/ast/scratch.py index ba738f64c..02c109fd0 100644 --- a/pyteal/ast/scratch.py +++ b/pyteal/ast/scratch.py @@ -1,12 +1,12 @@ from typing import cast, TYPE_CHECKING, Optional -from ..types import TealType, require_type -from ..config import NUM_SLOTS -from ..errors import TealInputError, TealInternalError -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.config import NUM_SLOTS +from pyteal.errors import TealInputError, TealInternalError +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class ScratchSlot: @@ -87,7 +87,7 @@ def has_return(self): return False def __teal__(self, options: "CompileOptions"): - from ..ir import TealOp, Op, TealBlock + from pyteal.ir import TealOp, Op, TealBlock op = TealOp(self, Op.int, self.slot) return TealBlock.FromOp(options, op) @@ -143,7 +143,7 @@ def __str__(self): return "(Load {})".format(self.slot if self.slot else self.index_expression) def __teal__(self, options: "CompileOptions"): - from ..ir import TealOp, Op, TealBlock + from pyteal.ir import TealOp, Op, TealBlock if self.index_expression is not None: op = TealOp(self, Op.loads) @@ -203,7 +203,7 @@ def __str__(self): ) def __teal__(self, options: "CompileOptions"): - from ..ir import TealOp, Op, TealBlock + from pyteal.ir import TealOp, Op, TealBlock if self.index_expression is not None: op = TealOp(self, Op.stores) @@ -246,7 +246,7 @@ def __str__(self): return "(StackStore {})".format(self.slot) def __teal__(self, options: "CompileOptions"): - from ..ir import TealOp, Op, TealBlock + from pyteal.ir import TealOp, Op, TealBlock op = TealOp(self, Op.store, self.slot) return TealBlock.FromOp(options, op) diff --git a/pyteal/ast/scratchvar.py b/pyteal/ast/scratchvar.py index 9b335e6bf..81ce27fff 100644 --- a/pyteal/ast/scratchvar.py +++ b/pyteal/ast/scratchvar.py @@ -1,8 +1,8 @@ -from ..errors import TealInputError -from ..types import TealType, require_type +from pyteal.errors import TealInputError +from pyteal.types import TealType, require_type -from .expr import Expr -from .scratch import ScratchSlot, ScratchLoad, ScratchStore +from pyteal.ast.expr import Expr +from pyteal.ast.scratch import ScratchSlot, ScratchLoad, ScratchStore class ScratchVar: diff --git a/pyteal/ast/seq.py b/pyteal/ast/seq.py index 15ca8efc1..4185cd5cc 100644 --- a/pyteal/ast/seq.py +++ b/pyteal/ast/seq.py @@ -1,12 +1,12 @@ from typing import List, TYPE_CHECKING, overload -from ..types import TealType, require_type -from ..errors import TealInputError -from ..ir import TealSimpleBlock -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.errors import TealInputError +from pyteal.ir import TealSimpleBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Seq(Expr): diff --git a/pyteal/ast/subroutine.py b/pyteal/ast/subroutine.py index baa7d3db4..c92dc4625 100644 --- a/pyteal/ast/subroutine.py +++ b/pyteal/ast/subroutine.py @@ -14,17 +14,17 @@ Any, ) -from ..errors import TealInputError, verifyTealVersion -from ..ir import TealOp, Op, TealBlock -from ..types import TealType +from pyteal.errors import TealInputError, verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.types import TealType -from .expr import Expr -from .seq import Seq -from .scratchvar import DynamicScratchVar, ScratchVar -from . import abi +from pyteal.ast import abi +from pyteal.ast.expr import Expr +from pyteal.ast.seq import Seq +from pyteal.ast.scratchvar import DynamicScratchVar, ScratchVar if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class SubroutineDefinition: diff --git a/pyteal/ast/subroutine_test.py b/pyteal/ast/subroutine_test.py index 21857f1dd..9f1f91c7b 100644 --- a/pyteal/ast/subroutine_test.py +++ b/pyteal/ast/subroutine_test.py @@ -2,7 +2,7 @@ import pytest import pyteal as pt -from .subroutine import evaluateSubroutine +from pyteal.ast.subroutine import evaluateSubroutine options = pt.CompileOptions(version=4) diff --git a/pyteal/ast/substring.py b/pyteal/ast/substring.py index a9fd8b1f8..438b40933 100644 --- a/pyteal/ast/substring.py +++ b/pyteal/ast/substring.py @@ -1,14 +1,14 @@ from typing import cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..errors import TealCompileError, verifyTealVersion -from ..ir import TealOp, Op, TealBlock, TealSimpleBlock -from .expr import Expr -from .int import Int -from .ternaryexpr import TernaryExpr +from pyteal.types import TealType, require_type +from pyteal.errors import TealCompileError, verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock, TealSimpleBlock +from pyteal.ast.expr import Expr +from pyteal.ast.int import Int +from pyteal.ast.ternaryexpr import TernaryExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class SubstringExpr(Expr): diff --git a/pyteal/ast/ternaryexpr.py b/pyteal/ast/ternaryexpr.py index f07939c4a..b329165de 100644 --- a/pyteal/ast/ternaryexpr.py +++ b/pyteal/ast/ternaryexpr.py @@ -1,12 +1,12 @@ from typing import Tuple, TYPE_CHECKING -from ..types import TealType, require_type -from ..errors import verifyTealVersion -from ..ir import TealOp, Op, TealBlock -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.errors import verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class TernaryExpr(Expr): diff --git a/pyteal/ast/tmpl.py b/pyteal/ast/tmpl.py index 9f6b0a99c..6d7061094 100644 --- a/pyteal/ast/tmpl.py +++ b/pyteal/ast/tmpl.py @@ -1,11 +1,11 @@ from typing import TYPE_CHECKING -from ..types import TealType, valid_tmpl -from ..ir import TealOp, Op, TealBlock -from .leafexpr import LeafExpr +from pyteal.types import TealType, valid_tmpl +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.leafexpr import LeafExpr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class Tmpl(LeafExpr): diff --git a/pyteal/ast/txn.py b/pyteal/ast/txn.py index d619ef0bc..e9182b74f 100644 --- a/pyteal/ast/txn.py +++ b/pyteal/ast/txn.py @@ -1,21 +1,21 @@ from enum import Enum from typing import Callable, Optional, Union, cast, TYPE_CHECKING -from ..types import TealType, require_type -from ..errors import ( +from pyteal.types import TealType, require_type +from pyteal.errors import ( TealInputError, TealCompileError, verifyFieldVersion, verifyTealVersion, ) -from ..ir import TealOp, Op, TealBlock -from .leafexpr import LeafExpr -from .expr import Expr -from .int import EnumInt -from .array import Array +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.leafexpr import LeafExpr +from pyteal.ast.expr import Expr +from pyteal.ast.int import EnumInt +from pyteal.ast.array import Array if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class TxnType: diff --git a/pyteal/ast/unaryexpr.py b/pyteal/ast/unaryexpr.py index 055339d1f..619bfab46 100644 --- a/pyteal/ast/unaryexpr.py +++ b/pyteal/ast/unaryexpr.py @@ -1,12 +1,12 @@ from typing import TYPE_CHECKING -from ..types import TealType, require_type -from ..errors import verifyTealVersion -from ..ir import TealOp, Op, TealBlock -from .expr import Expr +from pyteal.types import TealType, require_type +from pyteal.errors import verifyTealVersion +from pyteal.ir import TealOp, Op, TealBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class UnaryExpr(Expr): diff --git a/pyteal/ast/while_.py b/pyteal/ast/while_.py index f920c738c..5dd6fd09b 100644 --- a/pyteal/ast/while_.py +++ b/pyteal/ast/while_.py @@ -1,12 +1,12 @@ from typing import TYPE_CHECKING, Optional -from ..errors import TealCompileError -from ..types import TealType, require_type -from ..ir import TealSimpleBlock, TealConditionalBlock -from .expr import Expr +from pyteal.errors import TealCompileError +from pyteal.types import TealType, require_type +from pyteal.ir import TealSimpleBlock, TealConditionalBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions class While(Expr): diff --git a/pyteal/ast/widemath.py b/pyteal/ast/widemath.py index 25a0914ab..3098a7d3a 100644 --- a/pyteal/ast/widemath.py +++ b/pyteal/ast/widemath.py @@ -1,12 +1,12 @@ from typing import List, Tuple, TYPE_CHECKING -from ..types import TealType -from ..errors import TealInternalError, TealCompileError -from ..ir import TealOp, Op, TealSimpleBlock -from .expr import Expr +from pyteal.types import TealType +from pyteal.errors import TealInternalError, TealCompileError +from pyteal.ir import TealOp, Op, TealSimpleBlock +from pyteal.ast.expr import Expr if TYPE_CHECKING: - from ..compiler import CompileOptions + from pyteal.compiler import CompileOptions def multiplyFactors( diff --git a/pyteal/compiler/__init__.py b/pyteal/compiler/__init__.py index 74222f57c..13a3e6e92 100644 --- a/pyteal/compiler/__init__.py +++ b/pyteal/compiler/__init__.py @@ -1,4 +1,4 @@ -from .compiler import ( +from pyteal.compiler.compiler import ( MAX_TEAL_VERSION, MIN_TEAL_VERSION, DEFAULT_TEAL_VERSION, @@ -6,7 +6,7 @@ compileTeal, ) -from .optimizer import OptimizeOptions +from pyteal.compiler.optimizer import OptimizeOptions __all__ = [ "MAX_TEAL_VERSION", diff --git a/pyteal/compiler/compiler.py b/pyteal/compiler/compiler.py index beff7b8b0..d5a0174b2 100644 --- a/pyteal/compiler/compiler.py +++ b/pyteal/compiler/compiler.py @@ -1,29 +1,29 @@ from typing import List, Tuple, Set, Dict, Optional, cast -from .optimizer import OptimizeOptions, apply_global_optimizations +from pyteal.compiler.optimizer import OptimizeOptions, apply_global_optimizations -from ..types import TealType -from ..ast import ( +from pyteal.types import TealType +from pyteal.ast import ( Expr, Return, Seq, SubroutineDefinition, SubroutineDeclaration, ) -from ..ir import Mode, TealComponent, TealOp, TealBlock, TealSimpleBlock -from ..errors import TealInputError, TealInternalError +from pyteal.ir import Mode, TealComponent, TealOp, TealBlock, TealSimpleBlock +from pyteal.errors import TealInputError, TealInternalError -from .sort import sortBlocks -from .flatten import flattenBlocks, flattenSubroutines -from .scratchslots import ( +from pyteal.compiler.sort import sortBlocks +from pyteal.compiler.flatten import flattenBlocks, flattenSubroutines +from pyteal.compiler.scratchslots import ( assignScratchSlotsToSubroutines, collect_unoptimized_slots, ) -from .subroutines import ( +from pyteal.compiler.subroutines import ( spillLocalSlotsDuringRecursion, resolveSubroutines, ) -from .constants import createConstantBlocks +from pyteal.compiler.constants import createConstantBlocks MAX_TEAL_VERSION = 6 MIN_TEAL_VERSION = 2 diff --git a/pyteal/compiler/constants.py b/pyteal/compiler/constants.py index b2449d1d2..b47215588 100644 --- a/pyteal/compiler/constants.py +++ b/pyteal/compiler/constants.py @@ -4,13 +4,13 @@ from collections import OrderedDict from algosdk import encoding -from ..ir import ( +from pyteal.ir import ( Op, TealOp, TealComponent, ) -from ..util import unescapeStr, correctBase32Padding -from ..errors import TealInternalError +from pyteal.util import unescapeStr, correctBase32Padding +from pyteal.errors import TealInternalError intEnumValues = { # OnComplete values diff --git a/pyteal/compiler/constants_test.py b/pyteal/compiler/constants_test.py index d835c4c1e..e18b19208 100644 --- a/pyteal/compiler/constants_test.py +++ b/pyteal/compiler/constants_test.py @@ -1,6 +1,6 @@ import pyteal as pt -from .constants import ( +from pyteal.compiler.constants import ( extractIntValue, extractBytesValue, extractAddrValue, diff --git a/pyteal/compiler/flatten.py b/pyteal/compiler/flatten.py index 96cbebece..99674836c 100644 --- a/pyteal/compiler/flatten.py +++ b/pyteal/compiler/flatten.py @@ -1,8 +1,8 @@ from typing import List, Dict, DefaultDict, Optional from collections import defaultdict -from ..ast import SubroutineDefinition -from ..ir import ( +from pyteal.ast import SubroutineDefinition +from pyteal.ir import ( Op, TealOp, TealLabel, @@ -12,7 +12,7 @@ TealConditionalBlock, LabelReference, ) -from ..errors import TealInternalError +from pyteal.errors import TealInternalError def flattenBlocks(blocks: List[TealBlock]) -> List[TealComponent]: diff --git a/pyteal/compiler/flatten_test.py b/pyteal/compiler/flatten_test.py index 089a6ea48..a01c45d64 100644 --- a/pyteal/compiler/flatten_test.py +++ b/pyteal/compiler/flatten_test.py @@ -2,7 +2,7 @@ import pyteal as pt -from .flatten import flattenBlocks, flattenSubroutines +from pyteal.compiler.flatten import flattenBlocks, flattenSubroutines def test_flattenBlocks_none(): diff --git a/pyteal/compiler/optimizer/__init__.py b/pyteal/compiler/optimizer/__init__.py index 821f329d3..f12afea53 100644 --- a/pyteal/compiler/optimizer/__init__.py +++ b/pyteal/compiler/optimizer/__init__.py @@ -1 +1,4 @@ -from .optimizer import OptimizeOptions, apply_global_optimizations +from pyteal.compiler.optimizer.optimizer import ( + OptimizeOptions, + apply_global_optimizations, +) diff --git a/pyteal/compiler/optimizer/optimizer.py b/pyteal/compiler/optimizer/optimizer.py index 93a063ed5..056cfe699 100644 --- a/pyteal/compiler/optimizer/optimizer.py +++ b/pyteal/compiler/optimizer/optimizer.py @@ -1,7 +1,7 @@ from typing import Set -from ...ast import ScratchSlot -from ...ir import TealBlock, TealOp, Op -from ...errors import TealInternalError +from pyteal.ast import ScratchSlot +from pyteal.ir import TealBlock, TealOp, Op +from pyteal.errors import TealInternalError class OptimizeOptions: diff --git a/pyteal/compiler/optimizer/optimizer_test.py b/pyteal/compiler/optimizer/optimizer_test.py index 9da93bb88..f6f557471 100644 --- a/pyteal/compiler/optimizer/optimizer_test.py +++ b/pyteal/compiler/optimizer/optimizer_test.py @@ -1,4 +1,4 @@ -from .optimizer import OptimizeOptions, _apply_slot_to_stack +from pyteal.compiler.optimizer.optimizer import OptimizeOptions, _apply_slot_to_stack import pyteal as pt diff --git a/pyteal/compiler/scratchslots.py b/pyteal/compiler/scratchslots.py index bdc9d45a8..3d316b269 100644 --- a/pyteal/compiler/scratchslots.py +++ b/pyteal/compiler/scratchslots.py @@ -1,9 +1,9 @@ from typing import Tuple, Set, Dict, Optional, cast -from ..ast import ScratchSlot, SubroutineDefinition -from ..ir import TealBlock, Op -from ..errors import TealInternalError -from ..config import NUM_SLOTS +from pyteal.ast import ScratchSlot, SubroutineDefinition +from pyteal.ir import TealBlock, Op +from pyteal.errors import TealInternalError +from pyteal.config import NUM_SLOTS def collect_unoptimized_slots( diff --git a/pyteal/compiler/scratchslots_test.py b/pyteal/compiler/scratchslots_test.py index a9b545d26..5fee6c66a 100644 --- a/pyteal/compiler/scratchslots_test.py +++ b/pyteal/compiler/scratchslots_test.py @@ -2,7 +2,10 @@ import pyteal as pt -from .scratchslots import collectScratchSlots, assignScratchSlotsToSubroutines +from pyteal.compiler.scratchslots import ( + collectScratchSlots, + assignScratchSlotsToSubroutines, +) def test_collectScratchSlots(): diff --git a/pyteal/compiler/sort.py b/pyteal/compiler/sort.py index f4be9b98f..fc80070e9 100644 --- a/pyteal/compiler/sort.py +++ b/pyteal/compiler/sort.py @@ -1,7 +1,7 @@ from typing import List -from ..ir import TealBlock -from ..errors import TealInternalError +from pyteal.ir import TealBlock +from pyteal.errors import TealInternalError def sortBlocks(start: TealBlock, end: TealBlock) -> List[TealBlock]: diff --git a/pyteal/compiler/sort_test.py b/pyteal/compiler/sort_test.py index df23c6db6..fec49a6b4 100644 --- a/pyteal/compiler/sort_test.py +++ b/pyteal/compiler/sort_test.py @@ -1,6 +1,6 @@ import pyteal as pt -from .sort import sortBlocks +from pyteal.compiler.sort import sortBlocks def test_sort_single(): diff --git a/pyteal/compiler/subroutines.py b/pyteal/compiler/subroutines.py index c7b038d6e..bc3ee74e7 100644 --- a/pyteal/compiler/subroutines.py +++ b/pyteal/compiler/subroutines.py @@ -2,10 +2,10 @@ from typing import List, Dict, Set, Optional, TypeVar from collections import OrderedDict -from ..errors import TealInputError -from ..types import TealType -from ..ast import SubroutineDefinition -from ..ir import TealComponent, TealOp, Op +from pyteal.errors import TealInputError +from pyteal.types import TealType +from pyteal.ast import SubroutineDefinition +from pyteal.ir import TealComponent, TealOp, Op # generic type variable Node = TypeVar("Node") diff --git a/pyteal/compiler/subroutines_test.py b/pyteal/compiler/subroutines_test.py index cb444f872..bd3879a94 100644 --- a/pyteal/compiler/subroutines_test.py +++ b/pyteal/compiler/subroutines_test.py @@ -4,7 +4,7 @@ import pyteal as pt -from .subroutines import ( +from pyteal.compiler.subroutines import ( findRecursionPoints, spillLocalSlotsDuringRecursion, resolveSubroutines, diff --git a/pyteal/errors.py b/pyteal/errors.py index 4093819dd..bb238d98e 100644 --- a/pyteal/errors.py +++ b/pyteal/errors.py @@ -1,7 +1,7 @@ from typing import Optional, TYPE_CHECKING if TYPE_CHECKING: - from .ast import Expr + from pyteal.ast import Expr class TealInternalError(Exception): diff --git a/pyteal/ir/__init__.py b/pyteal/ir/__init__.py index 8107e4c30..e7db57cf8 100644 --- a/pyteal/ir/__init__.py +++ b/pyteal/ir/__init__.py @@ -1,13 +1,13 @@ -from .ops import Op, Mode +from pyteal.ir.ops import Op, Mode -from .tealcomponent import TealComponent -from .tealop import TealOp -from .teallabel import TealLabel -from .tealblock import TealBlock -from .tealsimpleblock import TealSimpleBlock -from .tealconditionalblock import TealConditionalBlock +from pyteal.ir.tealcomponent import TealComponent +from pyteal.ir.tealop import TealOp +from pyteal.ir.teallabel import TealLabel +from pyteal.ir.tealblock import TealBlock +from pyteal.ir.tealsimpleblock import TealSimpleBlock +from pyteal.ir.tealconditionalblock import TealConditionalBlock -from .labelref import LabelReference +from pyteal.ir.labelref import LabelReference __all__ = [ "Op", diff --git a/pyteal/ir/tealblock.py b/pyteal/ir/tealblock.py index 0743686eb..5fd2d5a42 100644 --- a/pyteal/ir/tealblock.py +++ b/pyteal/ir/tealblock.py @@ -2,14 +2,13 @@ from typing import Dict, List, Tuple, Set, Iterator, cast, TYPE_CHECKING - -from .tealop import TealOp, Op -from ..errors import TealCompileError +from pyteal.ir.tealop import TealOp, Op +from pyteal.errors import TealCompileError if TYPE_CHECKING: - from ..ast import Expr, ScratchSlot - from ..compiler import CompileOptions - from .tealsimpleblock import TealSimpleBlock + from pyteal.ast import Expr, ScratchSlot + from pyteal.compiler import CompileOptions + from pyteal.ir.tealsimpleblock import TealSimpleBlock class TealBlock(ABC): @@ -142,7 +141,7 @@ def FromOp( Returns: The starting and ending block of the path that encodes the given TealOp and arguments. """ - from .tealsimpleblock import TealSimpleBlock + from pyteal.ir.tealsimpleblock import TealSimpleBlock opBlock = TealSimpleBlock([op]) diff --git a/pyteal/ir/tealcomponent.py b/pyteal/ir/tealcomponent.py index e98c2bbe9..bb7755879 100644 --- a/pyteal/ir/tealcomponent.py +++ b/pyteal/ir/tealcomponent.py @@ -3,7 +3,7 @@ from contextlib import AbstractContextManager if TYPE_CHECKING: - from ..ast import Expr, ScratchSlot, SubroutineDefinition + from pyteal.ast import Expr, ScratchSlot, SubroutineDefinition class TealComponent(ABC): diff --git a/pyteal/ir/tealconditionalblock.py b/pyteal/ir/tealconditionalblock.py index bfbb3065c..2b4d6a790 100644 --- a/pyteal/ir/tealconditionalblock.py +++ b/pyteal/ir/tealconditionalblock.py @@ -1,7 +1,7 @@ from typing import Optional, List -from .tealop import TealOp -from .tealblock import TealBlock +from pyteal.ir.tealop import TealOp +from pyteal.ir.tealblock import TealBlock class TealConditionalBlock(TealBlock): diff --git a/pyteal/ir/teallabel.py b/pyteal/ir/teallabel.py index 12319269d..6c6cea98e 100644 --- a/pyteal/ir/teallabel.py +++ b/pyteal/ir/teallabel.py @@ -1,10 +1,10 @@ from typing import Optional, TYPE_CHECKING -from .tealcomponent import TealComponent -from .labelref import LabelReference +from pyteal.ir.tealcomponent import TealComponent +from pyteal.ir.labelref import LabelReference if TYPE_CHECKING: - from ..ast import Expr + from pyteal.ast import Expr class TealLabel(TealComponent): diff --git a/pyteal/ir/tealop.py b/pyteal/ir/tealop.py index b5ca1ce31..3f4e8a2a8 100644 --- a/pyteal/ir/tealop.py +++ b/pyteal/ir/tealop.py @@ -1,12 +1,12 @@ from typing import Union, List, Optional, TYPE_CHECKING -from .tealcomponent import TealComponent -from .labelref import LabelReference -from .ops import Op -from ..errors import TealInternalError +from pyteal.ir.tealcomponent import TealComponent +from pyteal.ir.labelref import LabelReference +from pyteal.ir.ops import Op +from pyteal.errors import TealInternalError if TYPE_CHECKING: - from ..ast import Expr, ScratchSlot, SubroutineDefinition + from pyteal.ast import Expr, ScratchSlot, SubroutineDefinition class TealOp(TealComponent): @@ -24,7 +24,7 @@ def getOp(self) -> Op: return self.op def getSlots(self) -> List["ScratchSlot"]: - from ..ast import ScratchSlot + from pyteal.ast import ScratchSlot return [arg for arg in self.args if isinstance(arg, ScratchSlot)] @@ -34,7 +34,7 @@ def assignSlot(self, slot: "ScratchSlot", location: int) -> None: self.args[i] = location def getSubroutines(self) -> List["SubroutineDefinition"]: - from ..ast import SubroutineDefinition + from pyteal.ast import SubroutineDefinition return [arg for arg in self.args if isinstance(arg, SubroutineDefinition)] @@ -44,7 +44,7 @@ def resolveSubroutine(self, subroutine: "SubroutineDefinition", label: str) -> N self.args[i] = label def assemble(self) -> str: - from ..ast import ScratchSlot, SubroutineDefinition + from pyteal.ast import ScratchSlot, SubroutineDefinition parts = [str(self.op)] for arg in self.args: @@ -81,7 +81,7 @@ def __eq__(self, other: object) -> bool: return False if not TealComponent.Context.checkScratchSlotEquality: - from ..ast import ScratchSlot + from pyteal import ScratchSlot if len(self.args) != len(other.args): return False diff --git a/pyteal/ir/tealsimpleblock.py b/pyteal/ir/tealsimpleblock.py index 6bd0285ab..e59c74377 100644 --- a/pyteal/ir/tealsimpleblock.py +++ b/pyteal/ir/tealsimpleblock.py @@ -1,7 +1,7 @@ from typing import Optional, List -from .tealop import TealOp -from .tealblock import TealBlock +from pyteal.ir.tealop import TealOp +from pyteal.ir.tealblock import TealBlock class TealSimpleBlock(TealBlock): diff --git a/pyteal/types.py b/pyteal/types.py index 169507ffa..63b61bd54 100644 --- a/pyteal/types.py +++ b/pyteal/types.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Any -from .errors import TealTypeError, TealInputError +from pyteal.errors import TealTypeError, TealInputError class TealType(Enum): diff --git a/pyteal/types_test.py b/pyteal/types_test.py index 2c1f61674..d42e60498 100644 --- a/pyteal/types_test.py +++ b/pyteal/types_test.py @@ -1,7 +1,7 @@ import pytest import pyteal as pt -from .types import require_type +from pyteal.types import require_type def test_require_type(): diff --git a/pyteal/util.py b/pyteal/util.py index 6dbbdb62e..614919fc6 100644 --- a/pyteal/util.py +++ b/pyteal/util.py @@ -1,4 +1,4 @@ -from .errors import TealInternalError +from pyteal.errors import TealInternalError def escapeStr(s: str) -> str: diff --git a/setup.py b/setup.py index 8d2d3103c..c09becbd9 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ "development": [ "black==22.3.0", "flake8==4.0.1", + "flake8-tidy-imports==4.6.0", "mypy==0.942", "pytest==7.1.1", "pytest-cov==3.0.0", From 45ad1efeaeeb66fdaa8be56cb68bf0eb5f348e61 Mon Sep 17 00:00:00 2001 From: Michael Diamant Date: Thu, 21 Apr 2022 17:39:45 -0400 Subject: [PATCH 11/11] Update CONTRIBUTING.md Co-authored-by: Zeph Grunschlag --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e9ed1daa2..eabd337fb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,7 +43,7 @@ A sibling module is defined as a different child module of the parent module. Fo #### In Runtime Code -When a runtime file in this codebase needs to import another module/file in this codebase, you should import the absolute path of the module/file, not the relative one, using the `from X import Y` method. +A file in this codebase that requires another module/file in this codebase, should import the absolute path of the module/file, not the relative one, using the `from X import Y` method. With regard to modules, there are two ways to import an object from this codebase: