Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__str__ formatting #411

Merged
merged 6 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyteal/ast/abi/bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def encode(self) -> Expr:
return SetBit(Bytes(b"\x00"), Int(0), self.get())


Bool.__module__ = "pyteal"


def boolAwareStaticByteLength(types: Sequence[TypeSpec]) -> int:
length = 0
ignoreNext = 0
Expand Down
3 changes: 3 additions & 0 deletions pyteal/ast/abi/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def _set_with_computed_type(self, value: "ComputedValue") -> Expr:
)
return value.store_into(self)

def __str__(self) -> str:
return str(self.type_spec())


BaseType.__module__ = "pyteal"

Expand Down
13 changes: 10 additions & 3 deletions pyteal/ast/abi/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ def test_size_of():
# Test for byte/bool/address/strings
(algosdk.abi.ByteType(), "byte", abi.ByteTypeSpec(), abi.Byte),
(algosdk.abi.BoolType(), "bool", abi.BoolTypeSpec(), abi.Bool),
(algosdk.abi.AddressType(), "address", abi.AddressTypeSpec(), abi.Address),
(
algosdk.abi.AddressType(),
"address",
abi.AddressTypeSpec(),
abi.Address,
),
(algosdk.abi.StringType(), "string", abi.StringTypeSpec(), abi.String),
# Test for dynamic array type
(
Expand Down Expand Up @@ -489,7 +494,6 @@ def test_size_of():
# ]
# ),
# ),
(algosdk.abi.TupleType([]), "()", abi.TupleTypeSpec(), abi.Tuple0),
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
(
"cannot map ABI transaction type spec <pyteal.TransactionTypeSpec",
"txn",
Expand Down Expand Up @@ -554,13 +558,16 @@ def test_size_of():


@pytest.mark.parametrize(
"algosdk_abi, abi_string, pyteal_abi_ts, pyteal_abi", ABI_TRANSLATION_TEST_CASES
"algosdk_abi, abi_string, pyteal_abi_ts, pyteal_abi",
ABI_TRANSLATION_TEST_CASES,
)
def test_abi_type_translation(algosdk_abi, abi_string, pyteal_abi_ts, pyteal_abi):
print(f"({algosdk_abi}, {abi_string}, {pyteal_abi_ts}),")

assert pyteal_abi_ts == abi.type_spec_from_annotation(pyteal_abi)

assert str(pyteal_abi_ts.new_instance()) == abi_string

if abi_string in (
"account",
"application",
Expand Down
4 changes: 3 additions & 1 deletion pyteal/ast/binaryexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def __teal__(self, options: "CompileOptions"):
)

def __str__(self):
return "({} {} {})".format(self.op, self.argLeft, self.argRight)
return "({} {} {})".format(
str(self.op).title().replace("_", ""), self.argLeft, self.argRight
)

def type_of(self):
return self.outputType
Expand Down
4 changes: 2 additions & 2 deletions pyteal/ast/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __teal__(self, options: "CompileOptions"):
return TealBlock.FromOp(options, op)

def __str__(self):
return "(Int: {})".format(self.value)
return "(Int {})".format(self.value)

def type_of(self):
return TealType.uint64
Expand All @@ -59,7 +59,7 @@ def __teal__(self, options: "CompileOptions"):
return TealBlock.FromOp(options, op)

def __str__(self):
return "(IntEnum: {})".format(self.name)
return "(IntEnum {})".format(self.name)

def type_of(self):
return TealType.uint64
Expand Down
2 changes: 1 addition & 1 deletion pyteal/ast/methodsig.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __teal__(self, options: "CompileOptions"):
return TealBlock.FromOp(options, op)

def __str__(self) -> str:
return "(method: {})".format(self.methodName)
return "(MethodSignature '{}')".format(self.methodName)

def type_of(self) -> TealType:
return TealType.bytes
Expand Down
2 changes: 1 addition & 1 deletion pyteal/ast/naryexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __teal__(self, options: "CompileOptions"):
return start, end

def __str__(self):
ret_str = "(" + str(self.op)
ret_str = "(" + str(self.op).title().replace("_", "")
for a in self.args:
ret_str += " " + a.__str__()
ret_str += ")"
Expand Down
2 changes: 1 addition & 1 deletion pyteal/ast/unaryexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __teal__(self, options: "CompileOptions"):
return TealBlock.FromOp(options, TealOp(self, self.op), self.arg)

def __str__(self):
return "({} {})".format(self.op, self.arg)
return "({} {})".format(str(self.op).title().replace("_", ""), self.arg)

def type_of(self):
return self.outputType
Expand Down