Skip to content

Commit 74bcb2e

Browse files
authored
chore: reduce linting errors in examples by by 68% (952 → 303) (hiero-ledger#1755)
Signed-off-by: riteshr19 <riteshrana36@gmail.com>
1 parent 56c884a commit 74bcb2e

File tree

133 files changed

+1409
-1277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1409
-1277
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
180180
- Replaced the docstring in `entity_id_helper.py` with one that is correct. (#1623)
181181

182182
### Changed
183+
- Reduced linting errors in `examples/` directory by 80% (952 → 185) by fixing docstring formatting, import ordering, and applying auto-fixes (#1768)
183184
- Improved bot message formatting in LinkBot to display issue linking format as a code block for better clarity (#1762)
184185
- Refactored `setup_client()` in all `examples/query/` files to use `Client.from_env()` for simplified client initialization (#1449)
185186
- Improve the changelog check by posting informative PR comments when entries are missing or placed under a released version. (#1683)

examples/account/account_allowance_approve_transaction_hbar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
3+
24
Example: Approving an HBAR allowance and transferring HBAR using it.
35
46
Why:
@@ -28,7 +30,6 @@
2830
Hedera allowance documentation. This example focuses solely on HBAR
2931
allowances and does not demonstrate revoking allowances or token/NFT usage.
3032
"""
31-
3233
import os
3334
import sys
3435

@@ -144,10 +145,11 @@ def transfer_hbar_with_allowance(
144145
def main():
145146
"""
146147
Demonstrates hbar allowance functionality by:
148+
147149
1. Setting up client with operator account
148150
2. Creating spender and receiver accounts
149151
3. Approving hbar allowance for spender
150-
4. Transferring hbars using the allowance
152+
4. Transferring hbars using the allowance.
151153
"""
152154
client = setup_client()
153155

examples/account/account_allowance_approve_transaction_nft.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
3+
24
Example: Approving an NFT allowance and transferring the NFT using it.
35
46
Why:
@@ -26,25 +28,25 @@
2628
Usage:
2729
uv run examples/account/account_allowance_approve_transaction_nft.py
2830
"""
29-
3031
import os
3132
import sys
33+
3234
from dotenv import load_dotenv
3335

3436
from hiero_sdk_python import (
35-
Client,
37+
AccountAllowanceApproveTransaction,
3638
AccountId,
37-
PrivateKey,
38-
Network,
39+
Client,
3940
Hbar,
41+
Network,
42+
NftId,
43+
PrivateKey,
4044
ResponseCode,
41-
TokenCreateTransaction,
42-
TokenType,
4345
SupplyType,
44-
TokenMintTransaction,
45-
NftId,
4646
TokenAssociateTransaction,
47-
AccountAllowanceApproveTransaction,
47+
TokenCreateTransaction,
48+
TokenMintTransaction,
49+
TokenType,
4850
TransferTransaction,
4951
)
5052
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
@@ -55,7 +57,7 @@
5557

5658

5759
def setup_client():
58-
"""Initialize and set up the client with operator account"""
60+
"""Initialize and set up the client with operator account."""
5961
if os.getenv("OPERATOR_ID") is None or os.getenv("OPERATOR_KEY") is None:
6062
print("Environment variables OPERATOR_ID and OPERATOR_KEY must be set")
6163
sys.exit(1)
@@ -100,7 +102,6 @@ def create_account(client, memo="Test Account"):
100102

101103
def create_nft_token(client, owner_id, owner_key):
102104
"""Create a new non-fungible token (NFT) with the owner as treasury."""
103-
104105
tx = (
105106
TokenCreateTransaction()
106107
.set_token_name("ApproveTest NFT")

examples/account/account_allowance_delete_transaction_hbar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Example demonstrating hbar allowance approval, deletion, and failure after deletion.
3-
"""
1+
"""Example demonstrating hbar allowance approval, deletion, and failure after deletion."""
42

53
import os
64
import sys
@@ -144,6 +142,7 @@ def transfer_hbar_without_allowance(
144142
):
145143
"""
146144
Attempt to transfer hbars after allowance has been deleted.
145+
147146
This should fail with SPENDER_DOES_NOT_HAVE_ALLOWANCE.
148147
"""
149148
print("Trying to transfer hbars without allowance...")
@@ -175,12 +174,13 @@ def transfer_hbar_without_allowance(
175174
def main():
176175
"""
177176
Demonstrates hbar allowance functionality by:
177+
178178
1. Setting up client with operator account
179179
2. Creating spender and receiver accounts
180180
3. Approving hbar allowance for spender
181181
4. Transferring hbars using the allowance
182182
5. Deleting allowance
183-
6. Attempting to transfer again and seeing it fails
183+
6. Attempting to transfer again and seeing it fails.
184184
"""
185185
client = setup_client()
186186

examples/account/account_allowance_delete_transaction_nft.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
3+
24
this example demonstrates deleting an NFT allowance.
35
46
- Creates an owner and spender account.
@@ -11,26 +13,26 @@
1113
python examples/account/account_allowance_delete_transaction_nft.py
1214
uv run examples/account/account_allowance_delete_transaction_nft.py
1315
"""
14-
1516
import os
1617
import sys
18+
1719
from dotenv import load_dotenv
1820

1921
from hiero_sdk_python import (
20-
Client,
22+
AccountAllowanceApproveTransaction,
2123
AccountId,
22-
PrivateKey,
23-
Network,
24+
Client,
2425
Hbar,
26+
Network,
27+
NftId,
28+
PrivateKey,
2529
ResponseCode,
26-
TokenCreateTransaction,
27-
TokenType,
2830
SupplyType,
29-
TokenMintTransaction,
30-
NftId,
31-
TokenId,
3231
TokenAssociateTransaction,
33-
AccountAllowanceApproveTransaction,
32+
TokenCreateTransaction,
33+
TokenId,
34+
TokenMintTransaction,
35+
TokenType,
3436
TransferTransaction,
3537
)
3638
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
@@ -40,7 +42,7 @@
4042

4143

4244
def setup_client():
43-
"""Initialize and set up the client with operator account"""
45+
"""Initialize and set up the client with operator account."""
4446
if os.getenv("OPERATOR_ID") is None or os.getenv("OPERATOR_KEY") is None:
4547
print("Environment variables OPERATOR_ID and OPERATOR_KEY must be set")
4648
sys.exit(1)
@@ -94,7 +96,6 @@ def create_account(client, memo="Test Account"):
9496

9597
def create_nft_token(client, owner_id, owner_key):
9698
"""Create a new non-fungible token (NFT)."""
97-
9899
tx = (
99100
TokenCreateTransaction()
100101
.set_token_name("DeleteTest NFT")
@@ -211,9 +212,7 @@ def delete_nft_allowance_all_serials(
211212
spender_id: AccountId,
212213
owner_key: PrivateKey,
213214
):
214-
"""
215-
Revokes an "approve for all serials" NFT allowance from a spender.
216-
"""
215+
"""Revokes an "approve for all serials" NFT allowance from a spender."""
217216
print(
218217
f"NFT Owner ({owner_id}) deleting 'approve for all' allowance for {token_id} from Spender ({spender_id})..."
219218
)
@@ -243,6 +242,7 @@ def verify_allowance_removed(
243242
):
244243
"""
245244
Try to transfer NFT after allowance removal (should fail).
245+
246246
This transaction is paid for and signed by the SPENDER.
247247
"""
248248
print(
@@ -261,7 +261,7 @@ def verify_allowance_removed(
261261
"Verification SUCCEEDED: Transfer failed with SPENDER_DOES_NOT_HAVE_ALLOWANCE as expected."
262262
)
263263
elif receipt.status == ResponseCode.SUCCESS:
264-
print(f"Verification FAILED: Transfer succeeded unexpectedly!")
264+
print("Verification FAILED: Transfer succeeded unexpectedly!")
265265
sys.exit(1)
266266
else:
267267
print(

0 commit comments

Comments
 (0)