Skip to content

Commit d32d076

Browse files
committed
chore: added type var to chunked transaction
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 4c5ec1d commit d32d076

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

src/hiero_sdk_python/transaction/chunked_transaction.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from abc import ABC, abstractmethod
4-
from typing import Literal, overload
4+
from typing import Literal, TypeVar, overload
55

66
from hiero_sdk_python.client.client import Client
77
from hiero_sdk_python.transaction.transaction import Transaction
@@ -10,6 +10,9 @@
1010
from hiero_sdk_python.transaction.transaction_response import TransactionResponse
1111

1212

13+
T = TypeVar("T", bound="ChunkedTransaction")
14+
15+
1316
class ChunkedTransaction(Transaction, ABC):
1417
"""
1518
Abstract base class for transactions that support chunking.
@@ -36,7 +39,7 @@ def __init__(self) -> None:
3639
self.max_chunks: int = 20
3740

3841
@abstractmethod
39-
def _build_proto_body(self):
42+
def _build_proto_body(self: T):
4043
"""
4144
Builds the protobuf body for the current chunk.
4245
@@ -52,7 +55,7 @@ def _build_proto_body(self):
5255
"""
5356
pass
5457

55-
def set_chunk_size(self, chunk_size: int) -> ChunkedTransaction:
58+
def set_chunk_size(self: T, chunk_size: int) -> T:
5659
"""
5760
Sets the chunk size for this transaction.
5861
@@ -73,7 +76,7 @@ def set_chunk_size(self, chunk_size: int) -> ChunkedTransaction:
7376
self._total_chunks = self.get_required_chunks()
7477
return self
7578

76-
def set_max_chunks(self, max_chunks: int) -> ChunkedTransaction:
79+
def set_max_chunks(self: T, max_chunks: int) -> T:
7780
"""
7881
Sets the maximum number of chunks allowed.
7982
@@ -93,7 +96,7 @@ def set_max_chunks(self, max_chunks: int) -> ChunkedTransaction:
9396
self.max_chunks = max_chunks
9497
return self
9598

96-
def _validate_chunking(self) -> None:
99+
def _validate_chunking(self: T) -> None:
97100
"""
98101
Validates that the transaction doesn't exceed the maximum number of chunks.
99102
@@ -106,7 +109,7 @@ def _validate_chunking(self) -> None:
106109
f"Required: {self.get_required_chunks()} Increase limit with set_max_chunks()."
107110
)
108111

109-
def freeze_with(self, client: Client) -> ChunkedTransaction:
112+
def freeze_with(self: T, client: Client) -> T:
110113
"""
111114
Freezes the transaction by building transaction bodies for all chunks.
112115
@@ -156,7 +159,7 @@ def freeze_with(self, client: Client) -> ChunkedTransaction:
156159

157160
@overload
158161
def execute(
159-
self,
162+
self: T,
160163
client: Client,
161164
timeout: int | float | None = None,
162165
wait_for_receipt: Literal[True] = True,
@@ -165,15 +168,15 @@ def execute(
165168

166169
@overload
167170
def execute(
168-
self,
171+
self: T,
169172
client: Client,
170173
timeout: int | float | None = None,
171174
wait_for_receipt: Literal[False] = False,
172175
validate_status: bool = False,
173176
) -> TransactionResponse: ...
174177

175178
def execute(
176-
self,
179+
self: T,
177180
client: Client,
178181
timeout: int | float | None = None,
179182
wait_for_receipt: bool = True,
@@ -200,7 +203,7 @@ def execute(
200203

201204
@overload
202205
def execute_all(
203-
self,
206+
self: T,
204207
client: Client,
205208
timeout: int | float | None = None,
206209
wait_for_receipt: Literal[True] = True,
@@ -209,15 +212,15 @@ def execute_all(
209212

210213
@overload
211214
def execute_all(
212-
self,
215+
self: T,
213216
client: Client,
214217
timeout: int | float | None = None,
215218
wait_for_receipt: Literal[False] = False,
216219
validate_status: bool = False,
217220
) -> list[TransactionResponse]: ...
218221

219222
def execute_all(
220-
self,
223+
self: T,
221224
client: Client,
222225
timeout: int | float | None = None,
223226
wait_for_receipt: bool = True,
@@ -258,7 +261,7 @@ def execute_all(
258261
return responses
259262

260263
@property
261-
def body_size_all_chunks(self) -> list[int]:
264+
def body_size_all_chunks(self: T) -> list[int]:
262265
"""
263266
Returns an array of body sizes for each chunk in the transaction.
264267

0 commit comments

Comments
 (0)