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 4 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
10 changes: 10 additions & 0 deletions pyteal/ast/abi/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def _set_with_computed_type(self, value: "ComputedValue") -> Expr:
)
return value.store_into(self)

def __str__(self) -> str:
at = self.type_spec().annotation_type()

# Check if the type is the same as the annotation type
# This suggests it is not generic and we can just use the class name
if type(self) is at:
return self.__class__.__name__

return str(at)


BaseType.__module__ = "pyteal"

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