Skip to content

Commit e574133

Browse files
committed
fix: reduce pyteal dependency, remove global ignores
1 parent fe52213 commit e574133

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

src/algokit_utils/application_client.py

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from typing import Any, cast
99

1010
import algosdk
11-
from algosdk import abi, transaction
11+
from algosdk import transaction
12+
from algosdk.abi import ABIType, Method, Returns # type: ignore[attr-defined]
1213
from algosdk.account import address_from_private_key
1314
from algosdk.atomic_transaction_composer import (
1415
ABI_RETURN_HASH,
@@ -25,7 +26,7 @@
2526
from algosdk.logic import get_application_address
2627
from algosdk.source_map import SourceMap
2728
from algosdk.v2client.algod import AlgodClient
28-
from pyteal import ABIReturnSubroutine, CallConfig, MethodConfig
29+
from pyteal import CallConfig, MethodConfig # TODO: remove PyTeal references
2930

3031
from algokit_utils.application_specification import (
3132
ApplicationSpecification,
@@ -35,10 +36,6 @@
3536
from algokit_utils.logic_error import LogicException, parse_logic_error
3637
from algokit_utils.state_decode import decode_state
3738

38-
# mypy: allow-untyped-calls,
39-
# mypy: disable_error_code = attr-defined
40-
# mypy: disable_error_code = name-defined
41-
4239

4340
class Program:
4441
"""A compiled TEAL program"""
@@ -49,7 +46,7 @@ def __init__(self, program: str, client: AlgodClient):
4946
source map for matching pc to line number
5047
"""
5148
self.teal = program
52-
result: dict = client.compile(self.teal, source_map=True)
49+
result: dict = client.compile(self.teal, source_map=True) # type: ignore[no-untyped-call]
5350
self.raw_binary = b64decode(result["result"])
5451
self.binary_hash: str = result["hash"]
5552
self.source_map = SourceMap(result["sourcemap"])
@@ -93,7 +90,7 @@ def __init__(
9390

9491
self.suggested_params = suggested_params
9592

96-
def find_method(predicate: Callable[[MethodConfig], bool]) -> abi.Method | None:
93+
def find_method(predicate: Callable[[MethodConfig], bool]) -> Method | None:
9794
matching = [
9895
method for method in self.app.contract.methods if predicate(self._method_hints(method).call_config)
9996
]
@@ -154,7 +151,7 @@ def create(
154151
else:
155152
atc.add_transaction(
156153
TransactionWithSigner(
157-
txn=transaction.ApplicationCreateTxn(
154+
txn=transaction.ApplicationCreateTxn( # type: ignore[no-untyped-call]
158155
sender=sender,
159156
sp=sp,
160157
on_complete=on_complete,
@@ -172,7 +169,7 @@ def create(
172169
create_result = self._execute_atc(atc)
173170
create_txid = create_result.tx_ids[0]
174171

175-
result = self.client.pending_transaction_info(create_txid)
172+
result = self.client.pending_transaction_info(create_txid) # type: ignore[no-untyped-call]
176173

177174
self._app_id = result["application-index"]
178175
self._app_address = get_application_address(self._app_id)
@@ -217,7 +214,7 @@ def replace(
217214
else:
218215
atc.add_transaction(
219216
TransactionWithSigner(
220-
txn=transaction.ApplicationCreateTxn(
217+
txn=transaction.ApplicationCreateTxn( # type: ignore[no-untyped-call]
221218
sender=sender,
222219
sp=sp,
223220
on_complete=on_complete,
@@ -245,7 +242,7 @@ def replace(
245242
else:
246243
atc.add_transaction(
247244
TransactionWithSigner(
248-
txn=transaction.ApplicationDeleteTxn(
245+
txn=transaction.ApplicationDeleteTxn( # type: ignore[no-untyped-call]
249246
sender=sender,
250247
sp=sp,
251248
index=self.app_id,
@@ -258,7 +255,7 @@ def replace(
258255
create_result = self._execute_atc(atc)
259256
create_txid = create_result.tx_ids[0]
260257

261-
result = self.client.pending_transaction_info(create_txid)
258+
result = self.client.pending_transaction_info(create_txid) # type: ignore[no-untyped-call]
262259

263260
self._app_id = result["application-index"]
264261
self._app_address = get_application_address(self._app_id)
@@ -293,7 +290,7 @@ def update(
293290
else:
294291
atc.add_transaction(
295292
TransactionWithSigner(
296-
txn=transaction.ApplicationUpdateTxn(
293+
txn=transaction.ApplicationUpdateTxn( # type: ignore[no-untyped-call]
297294
sender=sender,
298295
sp=sp,
299296
index=self.app_id,
@@ -333,7 +330,7 @@ def opt_in(
333330
else:
334331
atc.add_transaction(
335332
TransactionWithSigner(
336-
txn=transaction.ApplicationOptInTxn(
333+
txn=transaction.ApplicationOptInTxn( # type: ignore[no-untyped-call]
337334
sender=sender,
338335
sp=sp,
339336
index=self.app_id,
@@ -371,7 +368,7 @@ def close_out(
371368
else:
372369
atc.add_transaction(
373370
TransactionWithSigner(
374-
txn=transaction.ApplicationCloseOutTxn(
371+
txn=transaction.ApplicationCloseOutTxn( # type: ignore[no-untyped-call]
375372
sender=sender,
376373
sp=sp,
377374
index=self.app_id,
@@ -398,7 +395,7 @@ def clear_state(
398395
atc = AtomicTransactionComposer()
399396
atc.add_transaction(
400397
TransactionWithSigner(
401-
txn=transaction.ApplicationClearStateTxn(
398+
txn=transaction.ApplicationClearStateTxn( # type: ignore[no-untyped-call]
402399
sender=sender,
403400
sp=sp,
404401
index=self.app_id,
@@ -436,7 +433,7 @@ def delete(
436433
else:
437434
atc.add_transaction(
438435
TransactionWithSigner(
439-
txn=transaction.ApplicationDeleteTxn(
436+
txn=transaction.ApplicationDeleteTxn( # type: ignore[no-untyped-call]
440437
sender=sender,
441438
sp=sp,
442439
index=self.app_id,
@@ -467,7 +464,7 @@ def prepare(
467464

468465
def call(
469466
self,
470-
method: abi.Method | ABIReturnSubroutine | str,
467+
method: Method | str,
471468
sender: str | None = None,
472469
signer: TransactionSigner | None = None,
473470
suggested_params: transaction.SuggestedParams | None = None,
@@ -522,7 +519,7 @@ def call(
522519
# If its a read-only method, use dryrun (TODO: swap with simulate later?)
523520
if hints.read_only:
524521
dr_req = transaction.create_dryrun(self.client, atc.gather_signatures())
525-
dr_result = self.client.dryrun(dr_req)
522+
dr_result = self.client.dryrun(dr_req) # type: ignore[no-untyped-call]
526523
for txn in dr_result["txns"]:
527524
if "app-call-messages" in txn:
528525
if "REJECT" in txn["app-call-messages"]:
@@ -539,7 +536,7 @@ def call(
539536
def add_method_call(
540537
self,
541538
atc: AtomicTransactionComposer,
542-
method: abi.Method | ABIReturnSubroutine | str,
539+
method: Method | str,
543540
sender: str | None = None,
544541
signer: TransactionSigner | None = None,
545542
suggested_params: transaction.SuggestedParams | None = None,
@@ -618,10 +615,8 @@ def add_method_call(
618615

619616
return atc
620617

621-
def _resolve_abi_method(self, method: abi.Method | ABIReturnSubroutine | str) -> abi.Method:
622-
if isinstance(method, ABIReturnSubroutine):
623-
return method.method_spec()
624-
elif isinstance(method, str):
618+
def _resolve_abi_method(self, method: Method | str) -> Method:
619+
if isinstance(method, str):
625620
try:
626621
return next(iter(m for m in self.app.contract.methods if m.get_signature() == method))
627622
except StopIteration:
@@ -641,7 +636,7 @@ def add_transaction(
641636

642637
def get_global_state(self, *, raw: bool = False) -> dict[bytes | str, bytes | str | int]:
643638
"""gets the global state info for the app id set"""
644-
global_state = self.client.application_info(self.app_id)
639+
global_state = self.client.application_info(self.app_id) # type: ignore[no-untyped-call]
645640
return cast(
646641
dict[bytes | str, bytes | str | int],
647642
decode_state(global_state.get("params", {}).get("global-state", {}), raw=raw),
@@ -653,7 +648,7 @@ def get_local_state(self, account: str | None = None, *, raw: bool = False) -> d
653648
if account is None:
654649
_, account = self._resolve_signer_sender(self.signer, self.sender)
655650

656-
acct_state = self.client.account_application_info(account, self.app_id)
651+
acct_state = self.client.account_application_info(account, self.app_id) # type: ignore[no-untyped-call]
657652
if "app-local-state" not in acct_state or "key-value" not in acct_state["app-local-state"]:
658653
return {}
659654

@@ -664,7 +659,7 @@ def get_local_state(self, account: str | None = None, *, raw: bool = False) -> d
664659

665660
def get_application_account_info(self) -> dict[str, Any]:
666661
"""gets the account info for the application account"""
667-
return self.client.account_info(self.app_address) # type: ignore[no-any-return]
662+
return self.client.account_info(self.app_address) # type: ignore[no-untyped-call, no-any-return]
668663

669664
def get_box_names(self) -> list[bytes]:
670665
box_resp = self.client.application_boxes(self.app_id)
@@ -691,7 +686,7 @@ def _data_check(value: Any) -> int | str | bytes:
691686
acct_state = self.get_local_state(sender, raw=True)
692687
return acct_state[key.encode()]
693688
case {"source": "abi-method", "data": dict() as method_dict}:
694-
method = abi.Method.undictify(method_dict) # type: ignore[attr-defined]
689+
method = Method.undictify(method_dict)
695690
result = self.call(method)
696691
return _data_check(result.return_value)
697692

@@ -700,7 +695,7 @@ def _data_check(value: Any) -> int | str | bytes:
700695
case _:
701696
raise TypeError("Unable to interpret default argument specification")
702697

703-
def _method_hints(self, method: abi.Method) -> MethodHints:
698+
def _method_hints(self, method: Method) -> MethodHints:
704699
sig = method.get_signature()
705700
if sig not in self.app.hints:
706701
return MethodHints()
@@ -716,7 +711,7 @@ def get_suggested_params(
716711
if self.suggested_params is not None:
717712
return self.suggested_params
718713

719-
return self.client.suggested_params() # type: ignore[no-any-return]
714+
return self.client.suggested_params() # type: ignore[no-untyped-call, no-any-return]
720715

721716
def _execute_atc(self, atc: AtomicTransactionComposer, wait_rounds: int = 4) -> AtomicTransactionResponse:
722717
try:
@@ -750,9 +745,9 @@ def _resolve_signer_sender(
750745

751746
def _get_sender_from_signer(signer: TransactionSigner) -> str:
752747
if isinstance(signer, AccountTransactionSigner):
753-
return cast(str, address_from_private_key(signer.private_key))
748+
return cast(str, address_from_private_key(signer.private_key)) # type: ignore[no-untyped-call]
754749
elif isinstance(signer, MultisigTransactionSigner):
755-
return cast(str, signer.msig.address())
750+
return cast(str, signer.msig.address()) # type: ignore[no-untyped-call]
756751
elif isinstance(signer, LogicSigTransactionSigner):
757752
return signer.lsig.address()
758753
else:
@@ -761,7 +756,7 @@ def _get_sender_from_signer(signer: TransactionSigner) -> str:
761756

762757
# TEMPORARY, use SDK one when available
763758
def _parse_result(
764-
methods: dict[int, abi.Method],
759+
methods: dict[int, Method],
765760
txns: list[dict[str, Any]],
766761
txids: list[str],
767762
) -> list[ABIResult]:
@@ -776,7 +771,7 @@ def _parse_result(
776771

777772
# Parse log for ABI method return value
778773
try:
779-
if methods[i].returns.type == abi.Returns.VOID: # type: ignore[attr-defined]
774+
if methods[i].returns.type == Returns.VOID:
780775
method_results.append(
781776
ABIResult(
782777
tx_id=txids[i],
@@ -803,7 +798,7 @@ def _parse_result(
803798

804799
raw_value = result_bytes[4:]
805800
abi_return_type = methods[i].returns.type
806-
if isinstance(abi_return_type, abi.ABIType): # type: ignore[attr-defined]
801+
if isinstance(abi_return_type, ABIType):
807802
return_value = abi_return_type.decode(raw_value)
808803
else:
809804
return_value = raw_value

src/algokit_utils/application_specification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from algosdk.abi.method import MethodDict
99
from algosdk.transaction import StateSchema
1010
from algosdk.v2client.algod import AlgodClient
11-
from pyteal import CallConfig, MethodConfig
11+
from pyteal import CallConfig, MethodConfig # TODO: remove PyTeal references
1212

1313
__all__ = [
1414
"DefaultArgumentDict",

0 commit comments

Comments
 (0)