Skip to content

Commit 61234aa

Browse files
Subhrasameerdashom12prakash
authored andcommitted
chore: implement __repr__ method for FileId class (hiero-ledger#1628) (hiero-ledger#1770)
Signed-off-by: SubhraSameerDash <2303105_cseai@gita.edu.in> Signed-off-by: Subhra Sameer Dash <170787407+Subhrasameerdash@users.noreply.github.com>
1 parent 9fb07d5 commit 61234aa

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

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

3535
### Added
3636
- Added unit test and __repr__ for NftId class(#1627).
37+
- Implement custom `__repr__` method for `FileId` class that returns constructor-style representation for improved debugging experience (#1628)
3738
- Added foundational guide for GitHub Workflows (#1741)
3839
- Contract-specific CodeRabbit review instructions in `.coderabbit.yaml` for improved automated PR feedback on ABI, gas, ContractId, and protobuf safety. (#1695)
3940
- Added new members to the mentor roster. (#1693)

src/hiero_sdk_python/file/file_id.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def __str__(self) -> str:
106106
"""
107107
return f"{self.shard}.{self.realm}.{self.file}"
108108

109+
def __repr__(self) -> str:
110+
"""
111+
Returns a detailed representation of the FileId suitable for debugging.
112+
113+
Returns:
114+
str: A string in constructor format 'FileId(shard=X, realm=Y, file=Z)'.
115+
"""
116+
return f"FileId(shard={self.shard}, realm={self.realm}, file={self.file})"
117+
109118
def validate_checksum(self, client: Client) -> None:
110119
"""
111120
Validates the stored checksum against the calculated checksum using the provided client.

tests/unit/file_id_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ def test_str_representation_default():
4545
assert str(file_id) == "0.0.0"
4646

4747

48+
def test_repr_representation():
49+
"""Test repr representation of FileId."""
50+
file_id = FileId(0, 0, 150)
51+
assert repr(file_id) == "FileId(shard=0, realm=0, file=150)"
52+
53+
54+
def test_repr_representation_custom_values():
55+
"""Test repr representation of FileId with custom values."""
56+
file_id = FileId(shard=1, realm=2, file=3)
57+
assert repr(file_id) == "FileId(shard=1, realm=2, file=3)"
58+
59+
4860
def test_from_string_valid():
4961
"""Test creating FileId from valid string format."""
5062
file_id = FileId.from_string("1.2.3")

0 commit comments

Comments
 (0)