- 
                Notifications
    
You must be signed in to change notification settings  - Fork 86
 
Open
Description
Problem
Currently, the following classes in the src/hiero_sdk_python/tokens/ directory have str methods but are missing __repr__ methods:
- NftId (src/hiero_sdk_python/tokens/nft_id.py)
 - TokenTransfer (src/hiero_sdk_python/tokens/token_transfer.py)
 - TokenNftTransfer (src/hiero_sdk_python/tokens/token_nft_transfer.py)
 
According to Python best practices (PEP 257), classes should implement both str and __repr__ methods:
- str() - Returns a human-readable string representation
 __repr__()- Returns an unambiguous string representation that ideally could be used to recreate the object
Current State:
- All three classes have str implemented ✅
 - None of them have 
__repr__implemented ❌ 
Inconsistency:
Other similar classes in the same module already have __repr__ methods:
HbarTransferhas both str and__repr__HbarAllowancehas both str and__repr__TokenAllowancehas both str and__repr__TokenNftAllowancehas both str and__repr__
Proposed Solution
Add __repr__ methods to all three classes following the existing pattern used in other token classes.
Implementation Details
1. For NftId class (src/hiero_sdk_python/tokens/nft_id.py)
Add a __repr__ method after the existing str method (after line 135):
def __repr__(self) -> str:
    """
    Returns an unambiguous string representation of the NftId.
    
    Returns:
        str: A string that could be used to recreate the NftId object.
    """
    return f"NftId(token_id={self.token_id!r}, serial_number={self.serial_number!r})"2. For TokenTransfer class (src/hiero_sdk_python/tokens/token_transfer.py)
Add a __repr__ method after the existing str method (after line 70):
def __repr__(self) -> str:
    """
    Returns an unambiguous string representation of the TokenTransfer.
    
    Returns:
        str: A string that could be used to recreate the TokenTransfer object.
    """
    return (
        f"TokenTransfer("
        f"token_id={self.token_id!r}, "
        f"account_id={self.account_id!r}, "
        f"amount={self.amount!r}, "
        f"expected_decimals={self.expected_decimals!r}, "
        f"is_approved={self.is_approved!r})"
    )3. For TokenNftTransfer class (src/hiero_sdk_python/tokens/token_nft_transfer.py)
Add a __repr__ method after the existing str method (after line 95):
def __repr__(self) -> str:
    """
    Returns an unambiguous string representation of the TokenNftTransfer.
    
    Returns:
        str: A string that could be used to recreate the TokenNftTransfer object.
    """
    return (
        f"TokenNftTransfer("
        f"token_id={self.token_id!r}, "
        f"sender_id={self.sender_id!r}, "
        f"receiver_id={self.receiver_id!r}, "
        f"serial_number={self.serial_number!r}, "
        f"is_approved={self.is_approved!r})"
    )Benefits
- Consistency - Aligns with other token classes that already have 
__repr__ - Better Debugging - Provides clearer object representation in debuggers and logs
 - Python Best Practices - Follows PEP 257 guidelines
 - Developer Experience - Makes it easier to inspect objects during development
 
Acceptance Criteria
-  Add 
__repr__method to NftId class -  Add 
__repr__method to TokenTransfer class -  Add 
__repr__method to TokenNftTransfer class -  All 
__repr__methods include Google-style docstrings - Update CHANGELOG.md with the changes
 -  All commits are GPG signed (
-S) and DCO signed (-s) - Code passes pylint with 10/10 rating
 - All tests pass
 
Metadata
Metadata
Assignees
Labels
No labels