Skip to content

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

Description

@cheese-cakee

πŸ†•πŸ₯ Newcomer Friendly

This Good First Issue is a guided, well-scoped task intended for new contributors to the Hiero Python SDK.

What you'll do

  • βœ… understand how the repository is structured
  • βœ… practice the standard contribution workflow
  • βœ… submit and merge a pull request

Support

A maintainer or mentor actively monitors this issue and will help guide it to completion.

Important

This issue does not require prior domain knowledge.

  • No Hiero or Hedera experience needed
  • No distributed ledger background required
  • Basic Python and Git are sufficient

Note

⏱️ Typical time to complete: 30–60 minutes (once setup is done)
🧩 Difficulty: Small, well-contained change
πŸŽ“ Best for: New contributors

🏁 Completion
When this issue is complete, you will have:

  • βœ… Solved a real issue
  • βœ… A merged pull request in the Hiero Python SDK
  • βœ… Your name in the project history
  • βœ… Confidence to take on larger issues next

πŸ‘Ύ Description of the issue

The TokenId class in src/hiero_sdk_python/tokens/token_id.py has a __str__ method that returns shard.realm.num format, but it lacks a custom __repr__ method. The default dataclass __repr__ is used, which shows all fields including checksum=None even when not relevant.

When debugging, a clearer __repr__ that shows the constructor-style call would be more helpful:

>>> token_id = TokenId(0, 0, 123)
>>> repr(token_id)
# Current (default dataclass): "TokenId(shard=0, realm=0, num=123, checksum=None)"
# Desired: "TokenId(shard=0, realm=0, num=123)"

πŸ’‘ Proposed Solution

Implement a custom __repr__() method for the TokenId class that returns a clear, constructor-style representation. The checksum should not be shown (it's an internal detail).


πŸ‘©β€πŸ’» Implementation Steps

  • Open the file src/hiero_sdk_python/tokens/token_id.py

  • Review the existing __str__() method to understand the current formatting

  • Review the dataclass fields: shard, realm, num, checksum

  • Add a new __repr__() method after the existing __str__() method (around line 172):

    def __repr__(self) -> str:
        """
        Returns a detailed representation of the TokenId suitable for debugging.
    
        Returns:
            str: A string in constructor format 'TokenId(shard=X, realm=Y, num=Z)'.
        """
        return f"TokenId(shard={self.shard}, realm={self.realm}, num={self.num})"
  • Write a unit test for the new __repr__() method:

    def test_token_id_repr():
        token_id = TokenId(0, 0, 123)
        assert repr(token_id) == "TokenId(shard=0, realm=0, num=123)"
  • Run the tests to verify everything works: uv run pytest tests/


βœ… Acceptance Criteria

  • The issue is solved:
    My changes do exactly what the issue asked for.

  • I did not add extra changes:
    I did not modify anything that was not mentioned in the issue description.

  • Nothing else was broken:
    All existing features still work the same as before.

  • All checks pass:
    The automated tests (unit and integration tests) run successfully.


πŸ“‹ Step-by-Step Contribution Guide

  • Assignment: You must be assigned to the issue, comment: /assign in the issue to get assigned see guide
  • Fork, Branch and Work on the issue: Create a copy of the repository, create a branch for the issue and solve the problem. For instructions, please read our Contributing guide file. Further help can be found at Set-up Training (including the Windows Setup Guide for Windows users) and Workflow Training.
  • DCO and GPG key sign each commit : each commit must be -s and -S signed. An explanation on how to do this is at Signing Guide
  • Add a Changelog Entry : your pull request will require a changelog. Read Changelog Entry Guide to learn how.
  • Push and Create a Pull Request : Once your issue is resolved, and your commits are signed, and you have a changelog entry, push your changes and create a pull request. Detailed instructions can be found at Submit PR Training, part of Workflow Training.
  • You did it πŸŽ‰: A maintainer or committer will review your pull request and provide feedback. If approved, we will merge the fix in the main branch. Thanks for being part of the Hiero community as an open-source contributor ❀️

IMPORTANT You will ONLY be assigned to the issue if you comment: /assign
IMPORTANT Your pull request CANNOT BE MERGED until you add a changelog entry AND sign your commits each with git commit -S -s -m "chore: your commit message" with a GPG key setup.


πŸ€– AI Usage Guidelines

You are welcome to use AI to help you understand and solve this issue.

Because AI tools can sometimes make mistakes, please take care to:

  • Only implement what is described in this issue
  • Avoid changing anything else in the file
  • Be careful when modifying parameters or return statements, as this may affect runtime behavior

If you're unsure, ask your mentor or the maintainers for help β€” they can provide expert Python SDK guidance and point you to the right examples or methods.


πŸ€” Additional Information

For more help, we have extensive documentation:

Additionally, we invite you to join our community on our Discord server.

We also invite you to attend each Wednesday, 2pm UTC our Python SDK Office Hour and Community Calls. The Python SDK Office hour is for hands-on-help and the Community Call for general community discussion.

You can also ask for help in a comment below!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Good First IssueIssues which are ideal for a first time or new project contributor.lang: pythonUses Python programming language

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions