From 7e177f5cafa7d238cfe347937b898588ed07316c Mon Sep 17 00:00:00 2001 From: Jacob Daitzman Date: Thu, 10 Nov 2022 15:07:12 -0500 Subject: [PATCH] Fix type errors in `dryrun_results.py` --- algosdk/dryrun_results.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/algosdk/dryrun_results.py b/algosdk/dryrun_results.py index cc0efdd66..1c1c67408 100644 --- a/algosdk/dryrun_results.py +++ b/algosdk/dryrun_results.py @@ -1,5 +1,5 @@ import base64 -from typing import List +from typing import List, Optional, cast class StackPrinterConfig: @@ -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 @@ -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 "" @@ -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 ) @@ -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 ) @@ -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 @@ -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])