Skip to content

Commit 0fc6fcc

Browse files
authored
chore: Type improvements to account, address_book and consensus (#160)
* chore: type fixes account Signed-off-by: exploreriii <[email protected]> * chore: type fixes address_book Signed-off-by: exploreriii <[email protected]> * chore: type fixes consensus Signed-off-by: exploreriii <[email protected]> * fix: remove duplicate eq Signed-off-by: exploreriii <[email protected]> --------- Signed-off-by: exploreriii <[email protected]>
1 parent 20f6737 commit 0fc6fcc

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

src/hiero_sdk_python/account/account_balance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union, Dict
1+
from typing import Dict
22

33
from hiero_sdk_python.tokens.token_id import TokenId
44
from hiero_sdk_python.hbar import Hbar
@@ -42,7 +42,7 @@ def _from_proto(cls, proto: CryptoGetAccountBalanceResponse) -> "AccountBalance"
4242
if proto.tokenBalances:
4343
for token_balance in proto.tokenBalances:
4444
token_id: TokenId = TokenId._from_proto(token_balance.tokenId)
45-
balance: Union[Hbar,int] = token_balance.balance
45+
balance: int = token_balance.balance
4646
token_balances[token_id] = balance
4747

4848
return cls(hbars=hbars, token_balances=token_balances)

src/hiero_sdk_python/account/account_create_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def set_auto_renew_period(self, seconds: Union[int,Duration]) -> "AccountCreateT
103103
self.auto_renew_period = seconds
104104
else:
105105
raise TypeError("Duration of invalid type")
106-
106+
return self
107107

108108
def set_account_memo(self, memo: str) -> "AccountCreateTransaction":
109109
"""

src/hiero_sdk_python/account/account_id.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ def __repr__(self):
7272
"""
7373
return f"AccountId(shard={self.shard}, realm={self.realm}, num={self.num})"
7474

75-
def __eq__(self, other):
76-
if not isinstance(other, AccountId):
77-
return False
78-
return (self.shard, self.realm, self.num) == (other.shard, other.realm, other.num)
79-
8075
def __eq__(self, other: object) -> bool:
8176
"""
8277
Checks equality between two AccountId instances.

src/hiero_sdk_python/address_book/node_address.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import List, TypedDict
22

33
from hiero_sdk_python.account.account_id import AccountId
4-
from hiero_sdk_python.address_book.endpoint import Endpoint
4+
from hiero_sdk_python.address_book.endpoint import Endpoint, EndpointDict
55
from hiero_sdk_python.hapi.services.basic_types_pb2 import NodeAddress as NodeAddressProto
66

77
class NodeDict(TypedDict):
@@ -20,7 +20,7 @@ class NodeDict(TypedDict):
2020
node_account_id: str
2121
node_id: int
2222
node_cert_hash: str
23-
service_endpoints: List[Endpoint]
23+
service_endpoints: List[EndpointDict]
2424
description: str
2525

2626
class NodeAddress:
@@ -136,7 +136,7 @@ def _from_dict(cls, node: NodeDict) -> 'NodeAddress':
136136
Create a NodeAddress from a dictionary.
137137
"""
138138

139-
service_endpoints: List[Endpoint] = node.get('service_endpoints', [])
139+
service_endpoints: List[EndpointDict] = node.get('service_endpoints', [])
140140
public_key: str = node.get('public_key')
141141
account_id: AccountId = AccountId.from_string(node.get('node_account_id'))
142142
node_id: int = node.get('node_id')

src/hiero_sdk_python/consensus/topic_info.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from hiero_sdk_python.hapi.services.basic_types_pb2 import Key, AccountID
33
from hiero_sdk_python.hapi.services.timestamp_pb2 import Timestamp
44
from hiero_sdk_python.hapi.services import consensus_topic_info_pb2
5-
from hiero_sdk_python import Duration
5+
from hiero_sdk_python.Duration import Duration
66
from hiero_sdk_python.utils.key_format import format_key
7+
from typing import Optional
78

89
class TopicInfo:
910
def __init__(
@@ -12,11 +13,12 @@ def __init__(
1213
running_hash: bytes,
1314
sequence_number: int,
1415
expiration_time: Timestamp,
15-
admin_key: Key,
16-
submit_key: Key,
17-
auto_renew_period: Duration,
18-
auto_renew_account: AccountID,
19-
ledger_id: bytes,
16+
admin_key: Optional[Key],
17+
submit_key: Optional[Key],
18+
auto_renew_period: Optional[Duration],
19+
auto_renew_account: Optional[AccountID],
20+
ledger_id: Optional[bytes],
21+
2022
) -> None:
2123
"""
2224
Initializes a new instance of the TopicInfo class.
@@ -89,6 +91,9 @@ def __str__(self) -> str:
8991
exp_dt = datetime.fromtimestamp(self.expiration_time.seconds)
9092

9193
running_hash_hex: str = self.running_hash.hex() if self.running_hash else None
94+
ledger_id_hex: Optional[str] = (
95+
self.ledger_id.hex() if isinstance(self.ledger_id, (bytes, bytearray)) else None
96+
)
9297

9398
return (
9499
"TopicInfo(\n"
@@ -100,6 +105,6 @@ def __str__(self) -> str:
100105
f" submit_key={format_key(self.submit_key)},\n"
101106
f" auto_renew_period={self.auto_renew_period.seconds},\n"
102107
f" auto_renew_account={self.auto_renew_account},\n"
103-
f" ledger_id={self.ledger_id}\n"
108+
f" ledger_id=0x{ledger_id_hex}\n"
104109
")"
105110
)

src/hiero_sdk_python/consensus/topic_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, response: mirror_proto.ConsensusTopicResponse) -> None:
1717
Args:
1818
response: The ConsensusTopicResponse containing chunk data.
1919
"""
20-
self.consensus_timestamp: Timestamp = Timestamp._from_protobuf(response.consensusTimestamp).to_date()
20+
self.consensus_timestamp: datetime = Timestamp._from_protobuf(response.consensusTimestamp).to_date()
2121
self.content_size: int = len(response.message)
2222
self.running_hash: Union[bytes, int] = response.runningHash
2323
self.sequence_number: Union[bytes, int] = response.sequenceNumber

0 commit comments

Comments
 (0)