Skip to content

feat: add __repr__ to TokenId#1656

Draft
cnaples79 wants to merge 1 commit intohiero-ledger:mainfrom
cnaples79:fix/tokenid-repr
Draft

feat: add __repr__ to TokenId#1656
cnaples79 wants to merge 1 commit intohiero-ledger:mainfrom
cnaples79:fix/tokenid-repr

Conversation

@cnaples79
Copy link

@cnaples79 cnaples79 commented Jan 31, 2026

Summary

  • Implement custom __repr__() method for TokenId class
  • Returns constructor-style representation showing only shard, realm, and num (excludes internal checksum field)
  • Add unit tests to verify the __repr__() behavior

Rationale

Changes

  • src/hiero_sdk_python/tokens/token_id.py: implement __repr__() method
  • tests/unit/token_id_test.py: add test_token_id_repr() with multiple test cases
  • CHANGELOG.md: add entry under Unreleased → Added

Test Plan

  • Unit test added: test_token_id_repr() verifies correct output format
  • All existing tests continue to pass
  • CI checks passing

Fixes #1653

@github-actions
Copy link

[commit-verification-bot]
Hi, this is VerificationBot.
Your pull request cannot be merged as it has 1 unverified commit(s):

  • 90dc045 feat: add repr for TokenId

View your commit verification status: Commits Tab.

To achieve verified status, please read:

Remember, you require a GPG key and each commit must be signed with:
git commit -S -s -m "Your message here"

Thank you for contributing!

From the Hiero Python SDK Team

@cnaples79 cnaples79 marked this pull request as draft January 31, 2026 01:42
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

Walkthrough

Adds a custom TokenId.repr returning "TokenId(shard=X, realm=Y, num=Z)", a unit test for that repr, and a changelog entry documenting the addition. No other behavioral changes.

Changes

Cohort / File(s) Summary
Changelog Entry
CHANGELOG.md
Inserted an "Added" entry noting the developer-friendly __repr__ for TokenId in Unreleased.
TokenId repr Implementation
src/hiero_sdk_python/tokens/token_id.py
Added def __repr__(self) -> str returning TokenId(shard=..., realm=..., num=...); no other logic or validation changes.
Unit Test
tests/unit/token_id_test.py
Added test_token_id_repr asserting constructor-style repr for TokenId instances.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add repr to TokenId' clearly and concisely summarizes the main change: implementing a custom repr method for the TokenId class.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the rationale, changes made, and test plan for implementing repr for TokenId.
Linked Issues check ✅ Passed The PR fully satisfies the requirements from issue #1653: implements a custom repr method returning 'TokenId(shard=X, realm=Y, num=Z)' format, adds appropriate unit tests, and includes a changelog entry.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #1653 requirements: repr implementation in TokenId, unit test addition, and changelog entry. No out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hiero_sdk_python/tokens/token_id.py (1)

20-20: 🧹 Nitpick | 🔵 Trivial

Consider setting repr=False since a custom __repr__ is provided.

The dataclass decorator has repr=True, which generates an automatic __repr__. Since a custom implementation is now provided (line 182), the generated one is unused. Setting repr=False would make the intent clearer and avoid generating dead code.

♻️ Suggested change
-@dataclass(frozen=True, eq=True, init=True, repr=True)
+@dataclass(frozen=True, eq=True, init=True, repr=False)
 class TokenId:

Add custom __repr__ method that returns constructor-style representation
without the internal checksum field, improving debugging experience.

Also add unit tests to verify the __repr__ behavior.

Fixes hiero-ledger#1653

Signed-off-by: Chase Naples <Cnaples79@gmail.com>
@cnaples79 cnaples79 marked this pull request as ready for review January 31, 2026 02:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains merge conflicts.

Please resolve these conflicts locally and push the changes.

Quick Fix for CHANGELOG.md Conflicts

If your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:

  1. Click on the "Resolve conflicts" button in the PR
  2. Accept both changes (keep both changelog entries)
  3. Click "Mark as resolved"
  4. Commit the merge

For all other merge conflicts, please read:

Thank you for contributing!

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha the tests spotted something wrong!

We have checksums in token id, so we have a test that already checks for them:
test_nft_id

I think we can solve this by adding in the checksum into the repr, so it is not overriden
checksum=None

@exploreriii exploreriii marked this pull request as draft February 1, 2026 01:00
@exploreriii
Copy link
Contributor

@cnaples79 give me a bit of time please to suggest the best path forward
cc @manishdait

@manishdait
Copy link
Contributor

Hi @cnaples79, thanks for the updates — the PR looks good overall 👍
The only remaining blocker is the nft_id unit test. It currently compares the repr of TokenId using the old default behavior that includes checksum. Since TokenId.__repr__() has been customized, that test needs to be updated to reflect the new output.

Once the nft_id test is adjusted accordingly, this should be good to go.

Copy link
Contributor

@aceppaluni aceppaluni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cnaples79 Thank you for your work!

Once the changes are made we're happy to re-review.

Please let us know if you need assistance.

@exploreriii
Copy link
Contributor

Hi @cnaples79
The reason why the tests are failing is because by changing the repr method, some of the tests expected to see a checksum, so the tests need to be updated to expect the new repr - the logs will show you which tests please

@exploreriii exploreriii added the status: needs developer revision PR has requested changes that the developer needs to implement label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs developer revision PR has requested changes that the developer needs to implement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue]: Implement __repr__ Method for TokenId Class

4 participants