Skip to content

Commit a817a6f

Browse files
committed
feat: typing for misc
Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
1 parent abe06fe commit a817a6f

File tree

6 files changed

+34
-25
lines changed

6 files changed

+34
-25
lines changed

examples/query_topic_message.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from datetime import datetime, timezone
44
from dotenv import load_dotenv
55

6-
from hiero_sdk_python import Network, Client, TopicMessageQuery
6+
from hiero_sdk_python.client.network import Network
7+
from hiero_sdk_python.client.client import Client
8+
from hiero_sdk_python.query.topic_message_query import TopicMessageQuery
79

810
load_dotenv()
911

src/hiero_sdk_python/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"TopicDeleteTransaction",
164164
"TopicId",
165165

166-
# Queries
166+
# # Queries
167167
"TopicInfoQuery",
168168
"TopicMessageQuery",
169169
"TransactionGetReceiptQuery",
@@ -172,12 +172,12 @@
172172
"TokenNftInfoQuery",
173173
"TokenInfoQuery",
174174
"AccountInfoQuery",
175-
176-
# Address book
175+
176+
# # Address book
177177
"Endpoint",
178178
"NodeAddress",
179-
180-
# Logger
179+
180+
# # Logger
181181
"Logger",
182182
"LogLevel",
183183

src/hiero_sdk_python/_deprecated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class _DeprecatedAliasesMixin: # pylint: disable=too-few-public-methods
88
emitting a FutureWarning at use.
99
"""
1010

11-
_ALIASES = {
11+
_ALIASES: dict[str, str] = {
1212
"tokenId": "token_id",
1313
"totalSupply": "total_supply",
1414
"isDeleted": "is_deleted",
@@ -34,7 +34,7 @@ class _DeprecatedAliasesMixin: # pylint: disable=too-few-public-methods
3434
"fileId": "file_id"
3535
}
3636

37-
def __getattr__(self, name):
37+
def __getattr__(self, name: str) -> object:
3838
try:
3939
snake = self._ALIASES[name]
4040
except KeyError as exc:
@@ -49,7 +49,7 @@ def __getattr__(self, name):
4949
)
5050
return getattr(self, snake)
5151

52-
def __setattr__(self, name, value):
52+
def __setattr__(self, name: str, value: object) -> None:
5353
# intercept legacy writes
5454
if name in self._ALIASES:
5555
snake = self._ALIASES[name]

src/hiero_sdk_python/client/network.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Network module for managing Hedera SDK connections."""
22
import secrets
3-
from typing import Dict, List
3+
from typing import Dict, List, Optional, Any
44

55
import requests
66

@@ -64,9 +64,9 @@ class Network:
6464
def __init__(
6565
self,
6666
network: str = 'testnet',
67-
nodes: list[_Node] = None,
68-
mirror_address: str = None,
69-
):
67+
nodes: Optional[List[_Node]] = None,
68+
mirror_address: Optional[str] = None,
69+
) -> None:
7070
"""
7171
Initializes the Network with the specified network name or custom config.
7272
@@ -85,16 +85,20 @@ def __init__(
8585
)
8686

8787
if nodes is not None:
88-
self.nodes: List[_Node] = nodes
88+
final_nodes = nodes
8989
elif self.network in ('solo', 'localhost', 'local'):
90-
self.nodes: List[_Node] = self._fetch_nodes_from_default_nodes()
90+
final_nodes = self._fetch_nodes_from_default_nodes()
9191
else:
92-
self.nodes: List[_Node] = self._fetch_nodes_from_mirror_node()
93-
if not self.nodes and self.network in self.DEFAULT_NODES:
94-
self.nodes = self._fetch_nodes_from_default_nodes()
95-
elif not self.nodes:
92+
fetched = self._fetch_nodes_from_mirror_node()
93+
if not fetched and self.network in self.DEFAULT_NODES:
94+
final_nodes = self._fetch_nodes_from_default_nodes()
95+
elif fetched:
96+
final_nodes = fetched
97+
else:
9698
raise ValueError(f"No default nodes for network='{self.network}'")
9799

100+
self.nodes: List[_Node] = final_nodes
101+
98102
self._node_index: int = secrets.randbelow(len(self.nodes))
99103
self.current_node: _Node = self.nodes[self._node_index]
100104

@@ -104,7 +108,7 @@ def _fetch_nodes_from_mirror_node(self) -> List[_Node]:
104108
Returns:
105109
list: A list of _Node objects.
106110
"""
107-
base_url: str = self.MIRROR_NODE_URLS.get(self.network)
111+
base_url: Optional[str] = self.MIRROR_NODE_URLS.get(self.network)
108112
if not base_url:
109113
print(f"No known mirror node URL for network='{self.network}'. Skipping fetch.")
110114
return []
@@ -114,7 +118,7 @@ def _fetch_nodes_from_mirror_node(self) -> List[_Node]:
114118
try:
115119
response: requests.Response = requests.get(url, timeout=30) # Add 30 second timeout
116120
response.raise_for_status()
117-
data: dict = response.json()
121+
data: Dict[str, Any] = response.json()
118122

119123
nodes: List[_Node] = []
120124
# Process each node from the mirror node API response

src/hiero_sdk_python/executable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class _Method:
2828

2929
def __init__(
3030
self,
31-
query_func: Callable = None,
31+
query_func: Optional[Callable[..., Any]] = None,
3232
transaction_func: Optional[Callable[..., Any]] = None,
3333
):
3434
"""

src/hiero_sdk_python/response_code.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,21 @@ class ResponseCode(IntEnum):
350350
MAX_CUSTOM_FEES_IS_NOT_SUPPORTED = 387
351351

352352
@classmethod
353-
def _missing_(cls,value):
353+
def _missing_(cls, value: object) -> "ResponseCode":
354354
"""
355355
Handles cases where an integer value does not match any ResponseCode member
356356
and returns 'UNKNOWN_CODE_<value>'.
357357
"""
358-
unknown = int.__new__(cls,value)
358+
if not isinstance(value, int):
359+
raise ValueError(f"{value!r} is not a valid {cls.__name__}")
360+
361+
unknown = int.__new__(cls, value)
359362
unknown._name_ = f'UNKNOWN_CODE_{value}'
360363
unknown._value_ = value
361364
return unknown
362365

363366
@classmethod
364-
def get_name(cls,code):
367+
def get_name(cls,code: int) -> str:
365368
"""
366369
Returns the name of the response code.
367370
"""

0 commit comments

Comments
 (0)