Skip to content

Commit 55657d2

Browse files
feat: implement __repr__ method for TopicId class (#1661)
Signed-off-by: Ashhar Ahmad Khan <145142826+AshharAhmadKhan@users.noreply.github.com>
1 parent 2534698 commit 55657d2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2828
- Formatted client_test.py using Black.
2929

3030
### Added
31+
- Add `__repr__()` method to `TopicId` class for improved debugging with constructor-style representation (#1629)
3132
- Added guide for resolving CHANGELOG.md conflicts using GitHub's web editor (`#1591`)
32-
3333
- Added Windows setup guide for SDK developers (`docs/sdk_developers/training/setup/setup_windows.md`) with PowerShell installation instructions. (#1570)
3434
- Added a beginner assignment guard that requires completion of a Good First Issue. (#1484)
3535
- Added `/unassign` command allowing contributors to remove themselves from assigned issues.(#1472)

src/hiero_sdk_python/consensus/topic_id.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def __str__(self) -> str:
7575
"""
7676
return f"{self.shard}.{self.realm}.{self.num}"
7777

78+
def __repr__(self) -> str:
79+
"""
80+
Returns a detailed representation of the TopicId suitable for debugging.
81+
82+
Returns:
83+
str: A string in constructor format 'TopicId(shard=X, realm=Y, num=Z)'.
84+
"""
85+
return f"TopicId(shard={self.shard}, realm={self.realm}, num={self.num})"
86+
7887
@classmethod
7988
def from_string(cls, topic_id_str: str) -> "TopicId":
8089
"""

tests/unit/topic_id_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,8 @@ def test_validate_checksum_failure(client):
123123

124124
with pytest.raises(ValueError):
125125
topic_id.validate_checksum(client)
126+
127+
def test_topic_id_repr():
128+
"""Test that __repr__ returns the expected format."""
129+
topic_id = TopicId(0, 0, 42)
130+
assert repr(topic_id) == "TopicId(shard=0, realm=0, num=42)"

0 commit comments

Comments
 (0)