Skip to content

Commit e3b0776

Browse files
boblatdaniel-makerx
authored andcommitted
chore: trying to fix mypy issue
1 parent f69e3bb commit e3b0776

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/_algopy_testing/itxn.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ class InnerTransactionResult(_BaseInnerTransactionResult):
8686
pass
8787

8888

89-
class _BaseInnerTransactionFields:
89+
_TResult_co = typing.TypeVar(
90+
"_TResult_co",
91+
covariant=True,
92+
)
93+
94+
95+
class _BaseInnerTransactionFields(typing.Protocol[_TResult_co]):
9096
txn_class: type[_BaseInnerTransactionResult]
9197
fields: dict[str, typing.Any]
9298

@@ -107,10 +113,10 @@ def set(self, **fields: typing.Any) -> None:
107113
_narrow_covariant_types(fields)
108114
self.fields.update(fields)
109115

110-
def submit(self) -> typing.Any:
116+
def submit(self) -> _TResult_co:
111117
result = _get_itxn_result(self)
112118
lazy_context.active_group._add_itxn_group([result]) # type: ignore[list-item]
113-
return result
119+
return typing.cast("_TResult_co", result)
114120

115121
def copy(self) -> typing.Self:
116122
return deepcopy(self)
@@ -124,36 +130,36 @@ def _check_fields(fields: dict[str, object]) -> None:
124130
raise ValueError(f"unexpected fields: {','.join(fields.keys())}")
125131

126132

127-
class InnerTransaction(_BaseInnerTransactionFields):
133+
class InnerTransaction(_BaseInnerTransactionFields[InnerTransactionResult]):
128134
txn_class = InnerTransactionResult
129135

130136

131-
class Payment(_BaseInnerTransactionFields):
137+
class Payment(_BaseInnerTransactionFields[PaymentInnerTransaction]):
132138
txn_class = PaymentInnerTransaction
133139

134140

135-
class KeyRegistration(_BaseInnerTransactionFields):
141+
class KeyRegistration(_BaseInnerTransactionFields[KeyRegistrationInnerTransaction]):
136142
txn_class = KeyRegistrationInnerTransaction
137143

138144

139-
class AssetConfig(_BaseInnerTransactionFields):
145+
class AssetConfig(_BaseInnerTransactionFields[AssetConfigInnerTransaction]):
140146
txn_class = AssetConfigInnerTransaction
141147

142148

143-
class AssetTransfer(_BaseInnerTransactionFields):
149+
class AssetTransfer(_BaseInnerTransactionFields[AssetTransferInnerTransaction]):
144150
txn_class = AssetTransferInnerTransaction
145151

146152

147-
class AssetFreeze(_BaseInnerTransactionFields):
153+
class AssetFreeze(_BaseInnerTransactionFields[AssetFreezeInnerTransaction]):
148154
txn_class = AssetFreezeInnerTransaction
149155

150156

151-
class ApplicationCall(_BaseInnerTransactionFields):
157+
class ApplicationCall(_BaseInnerTransactionFields[ApplicationCallInnerTransaction]):
152158
txn_class = ApplicationCallInnerTransaction
153159

154160

155161
def submit_txns(
156-
*transactions: _BaseInnerTransactionFields,
162+
*transactions: _BaseInnerTransactionFields[_TResult_co],
157163
) -> tuple[_BaseInnerTransactionResult, ...]:
158164
if len(transactions) > algosdk.constants.TX_GROUP_LIMIT:
159165
raise ValueError("Cannot submit more than 16 inner transactions at once")
@@ -164,7 +170,9 @@ def submit_txns(
164170
return results
165171

166172

167-
def _get_itxn_result(itxn: _BaseInnerTransactionFields) -> _BaseInnerTransactionResult:
173+
def _get_itxn_result(
174+
itxn: _BaseInnerTransactionFields[_TResult_co],
175+
) -> _BaseInnerTransactionResult:
168176
fields = itxn.fields
169177
txn_type = fields["type"]
170178
result = _TXN_HANDLERS[txn_type](fields)

0 commit comments

Comments
 (0)