Skip to content

Commit ee0814d

Browse files
authored
refactor: converted class in TokenNftInfo to dataclass (#451)
* refactor: converted class in TokenNftInfo to dataclass Signed-off-by: Gargi Gupta <[email protected]> * Updated changelog for TokenNFTInfo dataclass refactor Signed-off-by: Gargi Gupta <[email protected]> * fix: addressed review feedback Signed-off-by: Gargi Gupta <[email protected]> --------- Signed-off-by: Gargi Gupta <[email protected]>
1 parent 3a089ec commit ee0814d

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
4040
- Refactored `examples/account_create.py` to improve modularity and readability (#363)
4141
- Replace Hendrik Ebbers with Sophie Bulloch in the MAINTAINERS.md file
4242
- Improved `CONTRIBUTING.md` by explaining the /docs folder structure and fixing broken hyperlinks.(#431)
43+
- Converted class in `token_nft_info.py` to dataclass for simplicity.
4344

4445

4546
### Fixed

src/hiero_sdk_python/tokens/token_nft_info.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from dataclasses import dataclass
12
"""
23
hiero_sdk_python.tokens.token_nft_info.py
34
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -10,37 +11,26 @@
1011
from hiero_sdk_python.tokens.nft_id import NftId
1112
from hiero_sdk_python.hapi.services import timestamp_pb2, token_get_nft_info_pb2
1213

14+
@dataclass
1315
class TokenNftInfo:
1416
"""
1517
Represents information about a Non-Fungible Token (NFT) on the Hedera network.
1618
17-
This class encapsulates details about an NFT including its unique identifier,
19+
This dataclass encapsulates details about an NFT including its unique identifier,
1820
owner account, creation time, associated metadata, and any account with spending privileges.
19-
"""
2021
21-
def __init__(
22-
self,
23-
nft_id: Optional[NftId] = None,
24-
account_id: Optional[AccountId] = None,
25-
creation_time: Optional[int] = None,
26-
metadata: Optional[bytes] = None,
27-
spender_id: Optional[AccountId] = None
28-
) -> None:
29-
"""
30-
Initialize a TokenNftInfo instance.
31-
32-
Args:
33-
nft_id (NftId, optional): The unique identifier of the NFT.
34-
account_id (AccountId, optional): The account ID of the NFT owner.
35-
creation_time (int, optional): The timestamp when the NFT was created (in seconds).
36-
metadata (bytes, optional): The metadata associated with the NFT.
37-
spender_id (AccountId, optional): The account ID with spending privileges for this NFT.
38-
"""
39-
self.nft_id: Optional[NftId] = nft_id
40-
self.account_id: Optional[AccountId] = account_id
41-
self.creation_time: Optional[int] = creation_time
42-
self.metadata: Optional[bytes] = metadata
43-
self.spender_id: Optional[AccountId] = spender_id
22+
Args:
23+
nft_id (NftId, optional): The unique identifier of the NFT.
24+
account_id (AccountId, optional): The account ID of the NFT owner.
25+
creation_time (int, optional): The timestamp when the NFT was created (in seconds).
26+
metadata (bytes, optional): The metadata associated with the NFT.
27+
spender_id (AccountId, optional): The account ID with spending privileges for this NFT
28+
"""
29+
nft_id: Optional[NftId] = None
30+
account_id: Optional[AccountId] = None
31+
creation_time: Optional[int] = None
32+
metadata: Optional[bytes] = None
33+
spender_id: Optional[AccountId] = None
4434

4535
@classmethod
4636
def _from_proto(cls, proto: token_get_nft_info_pb2.TokenNftInfo) -> "TokenNftInfo":
@@ -90,3 +80,4 @@ def __str__(self) -> str:
9080
f"creation_time={self.creation_time}, "
9181
f"metadata={self.metadata!r}, "
9282
f"spender_id={self.spender_id})")
83+

0 commit comments

Comments
 (0)