Skip to content

Commit 04b6ab3

Browse files
authored
fix: account pylint issues (#397)
* style: add type hints, format code and fix pylint issues in account_create_transaction.py Signed-off-by: dosi <[email protected]> * style: format account_balance.py and fix pylint issues Signed-off-by: dosi <[email protected]> * style: format account_delete_transaction.py and fix pylint issues Signed-off-by: dosi <[email protected]> * style: format account_id.py and fix pylint issues Signed-off-by: dosi <[email protected]> * style: format account_info.py and fix pylint issues Signed-off-by: dosi <[email protected]> * style: format account_update_transaction.py and fix pylint issues Signed-off-by: dosi <[email protected]> * chore: update CHANGELOG Signed-off-by: dosi <[email protected]> --------- Signed-off-by: dosi <[email protected]>
1 parent cc410fe commit 04b6ab3

File tree

7 files changed

+121
-82
lines changed

7 files changed

+121
-82
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
5858
- Add CI tests across Python 3.10–3.12.
5959

6060
### Fixed
61+
- Format account_create_transaction.py and add type hints
62+
- Format account_balance.py and fix pylint issues
63+
- Format account_delete_transaction.py and fix pylint issues
64+
- Format account_id.py and fix pylint issues
65+
- Format account_info.py and fix pylint issues
66+
- Format account_update_transaction.py and fix pylint issues
6167
- Unit test compatibility issues when running with UV package manager
6268
- Type annotations in TokenRelationship class (kyc_status and freeze_status)
6369
- Test assertions in test_executable.py using pytest match parameter

src/hiero_sdk_python/account/account_balance.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
"""
2+
AccountBalance class.
3+
"""
4+
15
from typing import Dict
26

3-
from hiero_sdk_python.tokens.token_id import TokenId
7+
from hiero_sdk_python.hapi.services.crypto_get_account_balance_pb2 import (
8+
CryptoGetAccountBalanceResponse,
9+
)
410
from hiero_sdk_python.hbar import Hbar
5-
from hiero_sdk_python.hapi.services.crypto_get_account_balance_pb2 import CryptoGetAccountBalanceResponse
11+
from hiero_sdk_python.tokens.token_id import TokenId
12+
613

714
class AccountBalance:
815
"""
@@ -13,7 +20,7 @@ class AccountBalance:
1320
token_balances (dict): A dictionary mapping TokenId to token balances.
1421
"""
1522

16-
def __init__(self, hbars: Hbar, token_balances: Dict[TokenId,int] = None) -> None:
23+
def __init__(self, hbars: Hbar, token_balances: Dict[TokenId, int] = None) -> None:
1724
"""
1825
Initializes the AccountBalance with the given hbar balance and token balances.
1926
@@ -25,7 +32,6 @@ def __init__(self, hbars: Hbar, token_balances: Dict[TokenId,int] = None) -> Non
2532
self.token_balances = token_balances or {}
2633

2734
@classmethod
28-
2935
def _from_proto(cls, proto: CryptoGetAccountBalanceResponse) -> "AccountBalance":
3036
"""
3137
Creates an AccountBalance instance from a protobuf response.
@@ -38,7 +44,7 @@ def _from_proto(cls, proto: CryptoGetAccountBalanceResponse) -> "AccountBalance"
3844
"""
3945
hbars: Hbar = Hbar.from_tinybars(tinybars=proto.balance)
4046

41-
token_balances: Dict[TokenId,int] = {}
47+
token_balances: Dict[TokenId, int] = {}
4248
if proto.tokenBalances:
4349
for token_balance in proto.tokenBalances:
4450
token_id: TokenId = TokenId._from_proto(token_balance.tokenId)

src/hiero_sdk_python/account/account_create_transaction.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from typing import Union
1+
"""
2+
AccountCreateTransaction class.
3+
"""
4+
5+
from typing import Optional, Union
26

37
from hiero_sdk_python.channels import _Channel
48
from hiero_sdk_python.crypto.public_key import PublicKey
@@ -11,6 +15,9 @@
1115
from hiero_sdk_python.hbar import Hbar
1216
from hiero_sdk_python.transaction.transaction import Transaction
1317

18+
AUTO_RENEW_PERIOD = Duration(7890000) # around 90 days in seconds
19+
DEFAULT_TRANSACTION_FEE = Hbar(3).to_tinybars() # 3 Hbars
20+
1421

1522
class AccountCreateTransaction(Transaction):
1623
"""
@@ -19,29 +26,30 @@ class AccountCreateTransaction(Transaction):
1926

2027
def __init__(
2128
self,
22-
key: PublicKey = None,
29+
key: Optional[PublicKey] = None,
2330
initial_balance: Union[Hbar, int] = 0,
24-
receiver_signature_required: bool = False,
25-
auto_renew_period: Duration = Duration(7890000), # 90 days in seconds
26-
memo: str = ""
27-
) -> None:
31+
receiver_signature_required: Optional[bool] = None,
32+
auto_renew_period: Optional[Duration] = AUTO_RENEW_PERIOD,
33+
memo: Optional[str] = None,
34+
) -> None:
2835
"""
29-
Initializes a new AccountCreateTransaction instance with default values or specified keyword arguments.
36+
Initializes a new AccountCreateTransaction instance with default values
37+
or specified keyword arguments.
3038
31-
Args:
32-
key (PublicKey, optional): The public key for the new account.
33-
initial_balance (Hbar or int, optional): Initial balance in Hbar or tinybars.
34-
receiver_signature_required (bool, optional): Whether receiver signature is required.
35-
auto_renew_period (int, optional): Auto-renew period in seconds (default is ~90 days).
36-
memo (str, optional): Memo for the account.
39+
Attributes:
40+
key (Optional[PublicKey]): The public key for the new account.
41+
initial_balance (Union[Hbar, int]): Initial balance in Hbar or tinybars.
42+
receiver_signature_required (Optional[bool]): Whether receiver signature is required.
43+
auto_renew_period (Duration): Auto-renew period in seconds (default is ~90 days).
44+
memo (Optional[str]): Memo for the account.
3745
"""
3846
super().__init__()
39-
self.key = key
40-
self.initial_balance = initial_balance
41-
self.receiver_signature_required = receiver_signature_required
42-
self.auto_renew_period = auto_renew_period
43-
self.account_memo = memo
44-
self._default_transaction_fee = 300_000_000
47+
self.key: Optional[PublicKey] = key
48+
self.initial_balance: Union[Hbar, int] = initial_balance
49+
self.receiver_signature_required: Optional[bool] = receiver_signature_required
50+
self.auto_renew_period: Optional[Duration] = auto_renew_period
51+
self.account_memo: Optional[str] = memo
52+
self._default_transaction_fee = DEFAULT_TRANSACTION_FEE
4553

4654
def set_key(self, key: PublicKey) -> "AccountCreateTransaction":
4755
"""
@@ -89,7 +97,7 @@ def set_receiver_signature_required(self, required: bool) -> "AccountCreateTrans
8997
self.receiver_signature_required = required
9098
return self
9199

92-
def set_auto_renew_period(self, seconds: Union[int,Duration]) -> "AccountCreateTransaction":
100+
def set_auto_renew_period(self, seconds: Union[int, Duration]) -> "AccountCreateTransaction":
93101
"""
94102
Sets the auto-renew period in seconds.
95103
@@ -148,7 +156,7 @@ def _build_proto_body(self):
148156
initialBalance=initial_balance_tinybars,
149157
receiverSigRequired=self.receiver_signature_required,
150158
autoRenewPeriod=duration_pb2.Duration(seconds=self.auto_renew_period.seconds),
151-
memo=self.account_memo
159+
memo=self.account_memo,
152160
)
153161

154162
def build_transaction_body(self) -> transaction_pb2.TransactionBody:
@@ -183,7 +191,4 @@ def _get_method(self, channel: _Channel) -> _Method:
183191
Returns:
184192
_Method: An instance of _Method containing the transaction and query functions.
185193
"""
186-
return _Method(
187-
transaction_func=channel.crypto.createAccount,
188-
query_func=None
189-
)
194+
return _Method(transaction_func=channel.crypto.createAccount, query_func=None)

src/hiero_sdk_python/account/account_delete_transaction.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def __init__(
4747
self.transfer_account_id: Optional[AccountId] = transfer_account_id
4848
self._default_transaction_fee = DEFAULT_TRANSACTION_FEE
4949

50-
def set_account_id(
51-
self, account_id: Optional[AccountId]
52-
) -> "AccountDeleteTransaction":
50+
def set_account_id(self, account_id: Optional[AccountId]) -> "AccountDeleteTransaction":
5351
"""
5452
Sets the ID of the account to delete.
5553
@@ -102,9 +100,7 @@ def _build_proto_body(self):
102100
return CryptoDeleteTransactionBody(
103101
deleteAccountID=self.account_id._to_proto(),
104102
transferAccountID=(
105-
self.transfer_account_id._to_proto()
106-
if self.transfer_account_id
107-
else None
103+
self.transfer_account_id._to_proto() if self.transfer_account_id else None
108104
),
109105
)
110106

src/hiero_sdk_python/account/account_id.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1+
"""
2+
AccountId class.
3+
"""
4+
15
from typing import List
26

37
from hiero_sdk_python.crypto.public_key import PublicKey
48
from hiero_sdk_python.hapi.services import basic_types_pb2
59

610

711
class AccountId:
12+
"""
13+
Represents an account ID on the network.
14+
15+
An account ID consists of three components: shard, realm, and num.
16+
These components uniquely identify an account in the network.
17+
18+
The standard format is `<shardNum>.<realmNum>.<accountNum>`, e.g., `0.0.10`.
19+
20+
In addition to the account number, the account component can also be an alias:
21+
- An alias can be either a public key (ED25519 or ECDSA)
22+
- The alias format is `<shardNum>.<realmNum>.<alias>`, where `alias` is the public key
23+
"""
24+
825
def __init__(
926
self, shard: int = 0, realm: int = 0, num: int = 0, alias_key: PublicKey = None
1027
) -> None:
@@ -28,9 +45,7 @@ def from_string(cls, account_id_str: str) -> "AccountId":
2845
"""
2946
parts: List[str] = account_id_str.strip().split(".")
3047
if len(parts) != 3:
31-
raise ValueError(
32-
"Invalid account ID string format. Expected 'shard.realm.num'"
33-
)
48+
raise ValueError("Invalid account ID string format. Expected 'shard.realm.num'")
3449
shard, realm, num = map(int, parts)
3550
return cls(shard, realm, num)
3651

@@ -51,7 +66,7 @@ def _from_proto(cls, account_id_proto: basic_types_pb2.AccountID) -> "AccountId"
5166
num=account_id_proto.accountNum,
5267
)
5368
if account_id_proto.alias:
54-
alias = account_id_proto.alias[2:] # remove 0x prefix
69+
alias = account_id_proto.alias[2:] # remove 0x prefix
5570
result.alias_key = PublicKey.from_bytes(alias)
5671
return result
5772

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
# pylint: disable=too-many-instance-attributes
2+
"""
3+
AccountInfo class.
4+
"""
5+
16
from dataclasses import dataclass, field
27
from typing import Optional
3-
from hiero_sdk_python.Duration import Duration
8+
49
from hiero_sdk_python.account.account_id import AccountId
510
from hiero_sdk_python.crypto.public_key import PublicKey
11+
from hiero_sdk_python.Duration import Duration
12+
from hiero_sdk_python.hapi.services.crypto_get_info_pb2 import CryptoGetInfoResponse
613
from hiero_sdk_python.hbar import Hbar
714
from hiero_sdk_python.timestamp import Timestamp
815
from hiero_sdk_python.tokens.token_relationship import TokenRelationship
9-
from hiero_sdk_python.hapi.services.crypto_get_info_pb2 import CryptoGetInfoResponse
16+
1017

1118
@dataclass
1219
class AccountInfo:
@@ -20,28 +27,33 @@ class AccountInfo:
2027
proxy_received (Optional[Hbar]): The total number of tinybars proxy staked to this account.
2128
key (Optional[PublicKey]): The key for this account.
2229
balance (Optional[Hbar]): The current balance of account in hbar.
23-
receiver_signature_required (Optional[bool]): If true, this account's key must sign any transaction depositing into this account.
24-
expiration_time (Optional[Timestamp]): The timestamp at which this account is set to expire.
25-
auto_renew_period (Optional[Duration]): The duration for which this account will automatically renew.
26-
token_relationships (list[TokenRelationship]): List of token relationships associated with this account.
30+
receiver_signature_required (Optional[bool]): If true, this account's key must sign
31+
any transaction depositing into this account.
32+
expiration_time (Optional[Timestamp]): The timestamp at which this account
33+
is set to expire.
34+
auto_renew_period (Optional[Duration]): The duration for which this account
35+
will automatically renew.
36+
token_relationships (list[TokenRelationship]): List of token relationships
37+
associated with this account.
2738
account_memo (Optional[str]): The memo associated with this account.
2839
owned_nfts (Optional[int]): The number of NFTs owned by this account.
2940
"""
30-
account_id : Optional[AccountId] = None
31-
contract_account_id : Optional[str] = None
32-
is_deleted : Optional[bool] = None
33-
proxy_received : Optional[Hbar] = None
34-
key : Optional[PublicKey] = None
35-
balance : Optional[Hbar] = None
36-
receiver_signature_required : Optional[bool] = None
37-
expiration_time : Optional[Timestamp] = None
38-
auto_renew_period : Optional[Duration] = None
39-
token_relationships : list[TokenRelationship] = field(default_factory=list)
40-
account_memo : Optional[str] = None
41-
owned_nfts : Optional[int] = None
42-
41+
42+
account_id: Optional[AccountId] = None
43+
contract_account_id: Optional[str] = None
44+
is_deleted: Optional[bool] = None
45+
proxy_received: Optional[Hbar] = None
46+
key: Optional[PublicKey] = None
47+
balance: Optional[Hbar] = None
48+
receiver_signature_required: Optional[bool] = None
49+
expiration_time: Optional[Timestamp] = None
50+
auto_renew_period: Optional[Duration] = None
51+
token_relationships: list[TokenRelationship] = field(default_factory=list)
52+
account_memo: Optional[str] = None
53+
owned_nfts: Optional[int] = None
54+
4355
@classmethod
44-
def _from_proto(cls, proto: CryptoGetInfoResponse.AccountInfo) -> 'AccountInfo':
56+
def _from_proto(cls, proto: CryptoGetInfoResponse.AccountInfo) -> "AccountInfo":
4557
if proto is None:
4658
raise ValueError("Account info proto is None")
4759

@@ -53,13 +65,20 @@ def _from_proto(cls, proto: CryptoGetInfoResponse.AccountInfo) -> 'AccountInfo':
5365
key=PublicKey._from_proto(proto.key) if proto.key else None,
5466
balance=Hbar.from_tinybars(proto.balance),
5567
receiver_signature_required=proto.receiverSigRequired,
56-
expiration_time=Timestamp._from_protobuf(proto.expirationTime) if proto.expirationTime else None,
57-
auto_renew_period=Duration._from_proto(proto.autoRenewPeriod) if proto.autoRenewPeriod else None,
58-
token_relationships=[TokenRelationship._from_proto(relationship) for relationship in proto.tokenRelationships],
68+
expiration_time=(
69+
Timestamp._from_protobuf(proto.expirationTime) if proto.expirationTime else None
70+
),
71+
auto_renew_period=(
72+
Duration._from_proto(proto.autoRenewPeriod) if proto.autoRenewPeriod else None
73+
),
74+
token_relationships=[
75+
TokenRelationship._from_proto(relationship)
76+
for relationship in proto.tokenRelationships
77+
],
5978
account_memo=proto.memo,
60-
owned_nfts=proto.ownedNfts
79+
owned_nfts=proto.ownedNfts,
6180
)
62-
81+
6382
def _to_proto(self) -> CryptoGetInfoResponse.AccountInfo:
6483
return CryptoGetInfoResponse.AccountInfo(
6584
accountID=self.account_id._to_proto() if self.account_id else None,
@@ -71,7 +90,9 @@ def _to_proto(self) -> CryptoGetInfoResponse.AccountInfo:
7190
receiverSigRequired=self.receiver_signature_required,
7291
expirationTime=self.expiration_time._to_protobuf() if self.expiration_time else None,
7392
autoRenewPeriod=self.auto_renew_period._to_proto() if self.auto_renew_period else None,
74-
tokenRelationships=[relationship._to_proto() for relationship in self.token_relationships],
93+
tokenRelationships=[
94+
relationship._to_proto() for relationship in self.token_relationships
95+
],
7596
memo=self.account_memo,
76-
ownedNfts=self.owned_nfts
77-
)
97+
ownedNfts=self.owned_nfts,
98+
)

src/hiero_sdk_python/account/account_update_transaction.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def __init__(self, account_params: Optional[AccountUpdateParams] = None):
7171
self.receiver_signature_required = params.receiver_signature_required
7272
self.expiration_time = params.expiration_time
7373

74-
def set_account_id(
75-
self, account_id: Optional[AccountId]
76-
) -> "AccountUpdateTransaction":
74+
def set_account_id(self, account_id: Optional[AccountId]) -> "AccountUpdateTransaction":
7775
"""
7876
Sets the `AccountId` that will be updated.
7977
@@ -117,9 +115,7 @@ def set_auto_renew_period(
117115
self.auto_renew_period = auto_renew_period
118116
return self
119117

120-
def set_account_memo(
121-
self, account_memo: Optional[str]
122-
) -> "AccountUpdateTransaction":
118+
def set_account_memo(self, account_memo: Optional[str]) -> "AccountUpdateTransaction":
123119
"""
124120
Sets the account memo (UTF-8, network enforced size limits apply).
125121
@@ -181,17 +177,11 @@ def _build_proto_body(self):
181177
return CryptoUpdateTransactionBody(
182178
accountIDToUpdate=self.account_id._to_proto(),
183179
key=self.key._to_proto() if self.key else None,
184-
memo=(
185-
StringValue(value=self.account_memo)
186-
if self.account_memo is not None
187-
else None
188-
),
180+
memo=StringValue(value=self.account_memo) if self.account_memo is not None else None,
189181
autoRenewPeriod=(
190182
self.auto_renew_period._to_proto() if self.auto_renew_period else None
191183
),
192-
expirationTime=(
193-
self.expiration_time._to_protobuf() if self.expiration_time else None
194-
),
184+
expirationTime=self.expiration_time._to_protobuf() if self.expiration_time else None,
195185
receiverSigRequiredWrapper=(
196186
BoolValue(value=self.receiver_signature_required)
197187
if self.receiver_signature_required is not None

0 commit comments

Comments
 (0)