Skip to content

Commit 158804a

Browse files
refactor: type id class refactor with dataclass decorator (#574)
Signed-off-by: Raghav Ganesh <[email protected]>
1 parent c757c1d commit 158804a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2626

2727
### Changed
2828

29+
- Refactored TopicId class to use @dataclass decorator for reducing boilerplate code
2930
- Renamed `examples/nft_allowance.py` to `examples/account_allowance_nft.py` for consistency with account class naming scheme
3031
- Added changelog conflict resolution examples to `docs/common_issues.md`
3132
- Refactored `examples/topic_create.py` to be more modular by splitting functions and renaming `create_topic()` to `main()`.

src/hiero_sdk_python/consensus/topic_id.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@
77
formats within the Hiero SDK.
88
"""
99

10+
from dataclasses import dataclass
11+
1012
from hiero_sdk_python.hapi.services import basic_types_pb2
1113

14+
@dataclass
1215
class TopicId:
13-
1416
"""
1517
Represents the unique identifier of a topic in the Hedera Consensus Service (HCS).
1618
1719
A `TopicId` consists of three components: shard, realm, and num.
1820
This class provides convenient methods for converting between Python objects,
1921
protobuf `TopicID` instances, and string formats.
22+
23+
Args:
24+
shard (int): The shard number of the topic. Defaults to 0.
25+
realm (int): The realm number of the topic. Defaults to 0.
26+
num (int): The topic number. Defaults to 0.
2027
"""
21-
def __init__(self, shard: int = 0, realm: int = 0, num: int = 0) -> None:
22-
"""
23-
Initializes a new instance of the TopicId class.
24-
Args:
25-
shard (int): The shard number of the topic.
26-
realm (int): The realm number of the topic.
27-
num (int): The topic number.
28-
"""
29-
self.shard: int = shard
30-
self.realm: int = realm
31-
self.num: int = num
28+
shard: int = 0
29+
realm: int = 0
30+
num: int = 0
3231

3332
@classmethod
3433
def _from_proto(cls, topic_id_proto: basic_types_pb2.TopicID) -> "TopicId":

0 commit comments

Comments
 (0)