Skip to content

Commit

Permalink
Fix type errors in dryrun_results.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jdtzmn committed Nov 10, 2022
1 parent 12838e7 commit 7e177f5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions algosdk/dryrun_results.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import base64
from typing import List
from typing import List, Optional, cast


class StackPrinterConfig:
Expand Down Expand Up @@ -63,13 +63,13 @@ def attrname(field):
def app_call_rejected(self) -> bool:
return (
False
if self.app_call_messages is None
else "REJECT" in self.app_call_messages
if self.app_call_messages is None # type: ignore # dynamic attribute
else "REJECT" in self.app_call_messages # type: ignore # dynamic attribute
)

def logic_sig_rejected(self) -> bool:
if self.logic_sig_messages is not None:
return "REJECT" in self.logic_sig_messages
if self.logic_sig_messages is not None: # type: ignore # dynamic attribute
return "REJECT" in self.logic_sig_messages # type: ignore # dynamic attribute
return False

@classmethod
Expand Down Expand Up @@ -123,16 +123,17 @@ def trace(

return "\n".join(trace) + "\n"

def app_trace(self, spc: StackPrinterConfig = None) -> str:
def app_trace(self, spc: Optional[StackPrinterConfig] = None) -> str:
if not hasattr(self, "app_call_trace"):
return ""

if spc == None:
spc = StackPrinterConfig(top_of_stack_first=False)
spc = cast(StackPrinterConfig, spc)

return self.trace(self.app_call_trace, self.disassembly, spc=spc)

def lsig_trace(self, spc: StackPrinterConfig = None) -> str:
def lsig_trace(self, spc: Optional[StackPrinterConfig] = None) -> str:
if not hasattr(self, "logic_sig_trace"):
return ""

Expand All @@ -143,7 +144,7 @@ def lsig_trace(self, spc: StackPrinterConfig = None) -> str:
spc = StackPrinterConfig(top_of_stack_first=False)

return self.trace(
self.logic_sig_trace, self.logic_sig_disassembly, spc=spc
self.logic_sig_trace, self.logic_sig_disassembly, spc=spc # type: ignore # dynamic attribute
)


Expand Down Expand Up @@ -182,10 +183,13 @@ def __str__(self) -> str:
return "0x" + base64.b64decode(self.bytes).hex()
return str(self.int)

def __eq__(self, other: "DryrunStackValue"):
def __eq__(self, other: object):
return (
self.type == other.type
hasattr(other, "type")
and self.type == other.type
and hasattr(other, "bytes")
and self.bytes == other.bytes
and hasattr(other, "int")
and self.int == other.int
)

Expand All @@ -202,7 +206,7 @@ def scratch_to_string(
if not curr_scratch:
return ""

new_idx = None
new_idx: Optional[int] = None
for idx in range(len(curr_scratch)):
if idx >= len(prev_scratch):
new_idx = idx
Expand All @@ -214,6 +218,7 @@ def scratch_to_string(
if new_idx == None:
return ""

new_idx = cast(int, new_idx) # discharge None type
return "{} = {}".format(new_idx, curr_scratch[new_idx])


Expand Down

0 comments on commit 7e177f5

Please sign in to comment.