-
Notifications
You must be signed in to change notification settings - Fork 151
style: apply black formatting to examples #1320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style: apply black formatting to examples #1320
Conversation
Signed-off-by: Dominiq Barbero <[email protected]>
📝 WalkthroughWalkthroughApply Black formatting across many example files (quote normalization, blank-line and line-wrap changes), add environment/operator validation and a few helper functions in select examples (account, contract, consensus, topic), and introduce mock-data builders and CLI entry points in several example modules. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
examples/contract/contract_delete_transaction.py (1)
64-70: Pre-existing: Consider addingfreeze_with(client)beforeexecute().Per SDK best practices, transactions should follow the lifecycle: construct →
freeze_with(client)→ sign (if needed) →execute(client). ThisFileCreateTransactionand subsequent contract transactions skipfreeze_with(). This is a pre-existing pattern—consider addressing in a follow-up issue rather than blocking this formatting PR.Would you like me to open a new issue to track adding proper
freeze_with()calls to this example?examples/account/account_create_transaction.py (1)
1-10: Optional: Consider restoring module docstring.The module docstring was removed (lines 1-2 now blank). While not blocking, examples typically benefit from a brief header explaining usage (e.g., "Example: Create a new Hedera account with initial balance"). This helps users understand what the example demonstrates at a glance.
examples/contract/contract_info_query.py (2)
36-42: Missingfreeze_with(client)in transaction lifecycle.The transaction executes without calling
freeze_with(client), violating the documented SDK lifecycle pattern (construct → freeze_with → sign → execute). Users copying this example will encounter unexpected behavior.🔎 Proposed fix
file_receipt = ( FileCreateTransaction() .set_keys(client.operator_private_key.public_key()) .set_contents(SIMPLE_CONTRACT_BYTECODE) .set_file_memo("Simple contract bytecode file") + .freeze_with(client) + .sign(client.operator_private_key) .execute(client) )As per coding guidelines, Priority 1-2: transaction lifecycle must include explicit
freeze_withand signing steps.
56-66: Missingfreeze_with(client)in transaction lifecycle.The contract creation executes without
freeze_with(client), breaking the required transaction lifecycle pattern. This prevents proper transaction finalization before execution.🔎 Proposed fix
receipt = ( ContractCreateTransaction() .set_admin_key(client.operator_private_key.public_key()) .set_initial_balance(1000) # 1000 tinybars .set_max_automatic_token_associations(10) .set_auto_renew_account_id(client.operator_account_id) .set_auto_renew_period(Duration(seconds=5184000)) # 60 days in seconds .set_gas(1000000) # 1M gas .set_bytecode_file_id(file_id) .set_contract_memo("Simple smart contract") + .freeze_with(client) + .sign(client.operator_private_key) .execute(client) )As per coding guidelines, Priority 1-2: all transactions must follow the construct → freeze_with → sign → execute pattern.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (64)
CHANGELOG.mdexamples/account/account_allowance_approve_transaction_hbar.pyexamples/account/account_allowance_approve_transaction_nft.pyexamples/account/account_allowance_delete_transaction_nft.pyexamples/account/account_create_transaction.pyexamples/account/account_create_transaction_create_with_alias.pyexamples/account/account_create_transaction_evm_alias.pyexamples/account/account_create_transaction_with_fallback_alias.pyexamples/account/account_create_transaction_without_alias.pyexamples/account/account_delete_transaction.pyexamples/account/account_id.pyexamples/account/account_info.pyexamples/account/account_records_query.pyexamples/account/account_update_transaction.pyexamples/client/client.pyexamples/consensus/topic_create_transaction.pyexamples/consensus/topic_create_transaction_revenue_generating.pyexamples/consensus/topic_delete_transaction.pyexamples/consensus/topic_id.pyexamples/consensus/topic_message.pyexamples/consensus/topic_message_submit_chunked_transaction.pyexamples/consensus/topic_message_submit_transaction.pyexamples/consensus/topic_update_transaction.pyexamples/contract/contract_bytecode_query.pyexamples/contract/contract_call_query.pyexamples/contract/contract_create_transaction_no_constructor_parameters.pyexamples/contract/contract_create_transaction_with_bytecode.pyexamples/contract/contract_create_transaction_with_constructor_parameters.pyexamples/contract/contract_delete_transaction.pyexamples/contract/contract_execute_transaction.pyexamples/contract/contract_execute_transaction_with_value.pyexamples/contract/contract_info_query.pyexamples/contract/contract_update_transaction.pyexamples/contract/ethereum_transaction.pyexamples/crypto/private_key_der.pyexamples/crypto/private_key_ecdsa.pyexamples/crypto/private_key_ed25519.pyexamples/crypto/public_key_der.pyexamples/crypto/public_key_ecdsa.pyexamples/crypto/public_key_ed25519.pyexamples/errors/receipt_status_error.pyexamples/file/file_append_transaction.pyexamples/file/file_contents_query.pyexamples/file/file_create_transaction.pyexamples/file/file_delete_transaction.pyexamples/file/file_info_query.pyexamples/file/file_update_transaction.pyexamples/hbar.pyexamples/logger/logging_example.pyexamples/prng_transaction.pyexamples/query/topic_info_query.pyexamples/query/transaction_get_receipt_query.pyexamples/response_code.pyexamples/schedule/schedule_create_transaction.pyexamples/schedule/schedule_delete_transaction.pyexamples/schedule/schedule_info_query.pyexamples/schedule/schedule_sign_transaction.pyexamples/tls_query_balance.pyexamples/topic_info.pyexamples/transaction/batch_transaction.pyexamples/transaction/transfer_transaction_gigabar.pyexamples/transaction/transfer_transaction_hbar.pyexamples/transaction/transfer_transaction_tinybar.pyexamples/utils.py
💤 Files with no reviewable changes (1)
- examples/account/account_allowance_approve_transaction_hbar.py
🧰 Additional context used
📓 Path-based instructions (1)
examples/**/*
⚙️ CodeRabbit configuration file
examples/**/*: You are acting as a senior maintainer reviewing SDK examples. Your goal is to ensure examples work verbatim for users who copy-paste them.Priority 1 - Correctness:
- Verify transaction lifecycle chain (construction -> freeze_with -> sign -> execute).
- Ensure
freeze_with(client)is called BEFORE signing.- Validate that methods referenced actually exist in the
hiero_sdk_pythoncodebase.- Ensure response validation checks
receipt.statusagainstResponseCodeenums (e.g.,ResponseCode.SUCCESS).Priority 2 - Transaction Lifecycle:
- Check method chaining logic.
- Verify correct signing order (especially for multi-sig).
- Ensure explicit
.execute(client)calls.- Verify response property extraction (e.g., using
.token_id,.account_id,.serial_numbers).- Ensure error handling uses
ResponseCode(receipt.status).namefor clarity.Priority 3 - Naming & Clarity:
- Enforce role-based naming:
operator_id/_key,treasury_account_id/_key,receiver_id/_key.- Use
_idsuffix for AccountId and_keysuffix for PrivateKey variables.- Validate negative examples explicitly check for failure codes (e.g.,
TOKEN_HAS_NO_PAUSE_KEY).- Ensure logical top-to-bottom flow without ambiguity.
Priority 4 - Consistency:
- Verify standard patterns:
def main(),if __name__ == "__main__":,load_dotenv().- IMPORT RULES:
- Accept both top-level imports (e.g.,
from hiero_sdk_python import PrivateKey) and fully qualified imports (e.g.,from hiero_sdk_python.crypto.private_key import PrivateKey).- STRICTLY validate that the import path actually exists in the project structure. Compare against other files in
/examplesor your knowledge of the SDK file tree.- Flag hallucinations immediately (e.g.,
hiero_sdk_python.keysdoes not exist).- Check for
try-exceptblocks withsys.exit(1)for critical failures.Priority 5 - User Experience:
- Ensure comments explain SDK usage patterns (for users,...
Files:
examples/transaction/batch_transaction.pyexamples/crypto/private_key_ecdsa.pyexamples/query/transaction_get_receipt_query.pyexamples/contract/contract_create_transaction_with_bytecode.pyexamples/contract/contract_call_query.pyexamples/query/topic_info_query.pyexamples/contract/contract_execute_transaction_with_value.pyexamples/tls_query_balance.pyexamples/contract/ethereum_transaction.pyexamples/contract/contract_info_query.pyexamples/schedule/schedule_info_query.pyexamples/consensus/topic_create_transaction_revenue_generating.pyexamples/account/account_records_query.pyexamples/prng_transaction.pyexamples/client/client.pyexamples/account/account_update_transaction.pyexamples/file/file_append_transaction.pyexamples/transaction/transfer_transaction_gigabar.pyexamples/schedule/schedule_create_transaction.pyexamples/transaction/transfer_transaction_hbar.pyexamples/file/file_create_transaction.pyexamples/account/account_delete_transaction.pyexamples/contract/contract_delete_transaction.pyexamples/file/file_contents_query.pyexamples/contract/contract_create_transaction_with_constructor_parameters.pyexamples/crypto/public_key_ecdsa.pyexamples/logger/logging_example.pyexamples/schedule/schedule_sign_transaction.pyexamples/contract/contract_execute_transaction.pyexamples/errors/receipt_status_error.pyexamples/crypto/private_key_der.pyexamples/account/account_create_transaction_without_alias.pyexamples/account/account_id.pyexamples/transaction/transfer_transaction_tinybar.pyexamples/account/account_create_transaction_create_with_alias.pyexamples/utils.pyexamples/contract/contract_bytecode_query.pyexamples/consensus/topic_message_submit_chunked_transaction.pyexamples/consensus/topic_delete_transaction.pyexamples/contract/contract_update_transaction.pyexamples/crypto/private_key_ed25519.pyexamples/contract/contract_create_transaction_no_constructor_parameters.pyexamples/account/account_info.pyexamples/crypto/public_key_ed25519.pyexamples/hbar.pyexamples/schedule/schedule_delete_transaction.pyexamples/file/file_update_transaction.pyexamples/account/account_allowance_approve_transaction_nft.pyexamples/crypto/public_key_der.pyexamples/account/account_create_transaction_evm_alias.pyexamples/account/account_create_transaction.pyexamples/file/file_info_query.pyexamples/consensus/topic_message_submit_transaction.pyexamples/response_code.pyexamples/consensus/topic_message.pyexamples/consensus/topic_update_transaction.pyexamples/file/file_delete_transaction.pyexamples/consensus/topic_create_transaction.pyexamples/consensus/topic_id.pyexamples/account/account_allowance_delete_transaction_nft.pyexamples/account/account_create_transaction_with_fallback_alias.pyexamples/topic_info.py
🧬 Code graph analysis (37)
examples/transaction/batch_transaction.py (2)
src/hiero_sdk_python/crypto/private_key.py (1)
public_key(305-309)src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)
examples/crypto/private_key_ecdsa.py (2)
tests/unit/conftest.py (1)
private_key(54-56)src/hiero_sdk_python/crypto/private_key.py (1)
PrivateKey(14-471)
examples/query/topic_info_query.py (3)
src/hiero_sdk_python/client/client.py (1)
Client(28-255)src/hiero_sdk_python/query/topic_info_query.py (1)
TopicInfoQuery(13-190)src/hiero_sdk_python/consensus/topic_create_transaction.py (1)
TopicCreateTransaction(27-243)
examples/tls_query_balance.py (2)
src/hiero_sdk_python/client/client.py (1)
set_transport_security(196-206)src/hiero_sdk_python/client/network.py (1)
set_transport_security(300-308)
examples/schedule/schedule_info_query.py (1)
src/hiero_sdk_python/schedule/schedule_info_query.py (1)
ScheduleInfoQuery(18-135)
examples/account/account_records_query.py (1)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)
examples/prng_transaction.py (1)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)
examples/file/file_append_transaction.py (2)
src/hiero_sdk_python/file/file_append_transaction.py (1)
FileAppendTransaction(37-388)src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)
examples/schedule/schedule_create_transaction.py (1)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)
examples/transaction/transfer_transaction_hbar.py (3)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)src/hiero_sdk_python/query/account_balance_query.py (1)
CryptoGetAccountBalanceQuery(10-138)src/hiero_sdk_python/transaction/transaction_receipt.py (1)
account_id(88-100)
examples/file/file_create_transaction.py (3)
examples/account/account_allowance_approve_transaction_nft.py (1)
setup_client(57-76)examples/account/account_update_transaction.py (1)
setup_client(26-37)examples/consensus/topic_create_transaction.py (1)
setup_client(24-53)
examples/account/account_delete_transaction.py (3)
src/hiero_sdk_python/hbar.py (1)
Hbar(18-213)src/hiero_sdk_python/account/account_delete_transaction.py (1)
AccountDeleteTransaction(20-145)src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)
examples/contract/contract_delete_transaction.py (2)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)src/hiero_sdk_python/hbar.py (2)
Hbar(18-213)from_tinybars(97-109)
examples/file/file_contents_query.py (1)
src/hiero_sdk_python/crypto/private_key.py (1)
public_key(305-309)
examples/crypto/public_key_ecdsa.py (2)
src/hiero_sdk_python/crypto/public_key.py (1)
PublicKey(22-556)src/hiero_sdk_python/utils/crypto_utils.py (1)
keccak256(18-27)
examples/logger/logging_example.py (2)
src/hiero_sdk_python/logger/logger.py (2)
set_level(56-78)set_silent(89-104)src/hiero_sdk_python/logger/log_level.py (1)
LogLevel(10-60)
examples/errors/receipt_status_error.py (3)
src/hiero_sdk_python/tokens/token_associate_transaction.py (1)
TokenAssociateTransaction(23-176)src/hiero_sdk_python/tokens/token_id.py (1)
TokenId(21-180)src/hiero_sdk_python/exceptions.py (1)
ReceiptStatusError(63-91)
examples/account/account_create_transaction_without_alias.py (1)
src/hiero_sdk_python/account/account_create_transaction.py (2)
AccountCreateTransaction(27-380)set_key_without_alias(94-107)
examples/transaction/transfer_transaction_tinybar.py (3)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)src/hiero_sdk_python/query/account_balance_query.py (1)
CryptoGetAccountBalanceQuery(10-138)src/hiero_sdk_python/transaction/transaction_receipt.py (1)
account_id(88-100)
examples/account/account_create_transaction_create_with_alias.py (3)
src/hiero_sdk_python/account/account_create_transaction.py (2)
AccountCreateTransaction(27-380)set_key_with_alias(109-135)src/hiero_sdk_python/query/account_info_query.py (1)
AccountInfoQuery(11-131)src/hiero_sdk_python/transaction/transaction_receipt.py (1)
account_id(88-100)
examples/consensus/topic_message_submit_chunked_transaction.py (2)
examples/consensus/topic_create_transaction.py (1)
setup_client(24-53)src/hiero_sdk_python/client/client.py (2)
Client(28-255)set_operator(149-154)
examples/consensus/topic_delete_transaction.py (2)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)src/hiero_sdk_python/consensus/topic_delete_transaction.py (1)
TopicDeleteTransaction(23-101)
examples/account/account_info.py (4)
src/hiero_sdk_python/account/account_id.py (1)
AccountId(21-198)src/hiero_sdk_python/hbar.py (1)
Hbar(18-213)src/hiero_sdk_python/timestamp.py (1)
Timestamp(8-166)src/hiero_sdk_python/account/account_info.py (1)
AccountInfo(20-208)
examples/crypto/public_key_ed25519.py (1)
src/hiero_sdk_python/crypto/public_key.py (3)
PublicKey(22-556)to_string_ed25519(434-439)verify(500-514)
examples/hbar.py (2)
src/hiero_sdk_python/hbar.py (2)
Hbar(18-213)from_string(160-179)src/hiero_sdk_python/hbar_unit.py (1)
from_string(33-47)
examples/account/account_allowance_approve_transaction_nft.py (4)
src/hiero_sdk_python/transaction/transfer_transaction.py (1)
TransferTransaction(24-238)src/hiero_sdk_python/tokens/nft_id.py (1)
NftId(17-105)src/hiero_sdk_python/account/account_allowance_approve_transaction.py (2)
AccountAllowanceApproveTransaction(27-396)approve_token_nft_allowance_all_serials(256-277)src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.py (1)
add_approved_nft_transfer(315-338)
examples/crypto/public_key_der.py (2)
src/hiero_sdk_python/crypto/public_key.py (2)
PublicKey(22-556)verify(500-514)src/hiero_sdk_python/utils/crypto_utils.py (1)
keccak256(18-27)
examples/account/account_create_transaction_evm_alias.py (2)
src/hiero_sdk_python/account/account_id.py (1)
AccountId(21-198)src/hiero_sdk_python/crypto/private_key.py (1)
PrivateKey(14-471)
examples/account/account_create_transaction.py (1)
src/hiero_sdk_python/client/client.py (3)
Client(28-255)from_env(54-98)close(184-194)
examples/file/file_info_query.py (1)
src/hiero_sdk_python/crypto/private_key.py (1)
public_key(305-309)
examples/consensus/topic_message_submit_transaction.py (2)
src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)src/hiero_sdk_python/consensus/topic_create_transaction.py (1)
TopicCreateTransaction(27-243)
examples/consensus/topic_message.py (1)
src/hiero_sdk_python/consensus/topic_message.py (4)
TopicMessage(34-192)TopicMessageChunk(14-31)of_single(66-89)of_many(92-142)
examples/consensus/topic_create_transaction.py (1)
src/hiero_sdk_python/crypto/private_key.py (1)
public_key(305-309)
examples/consensus/topic_id.py (1)
src/hiero_sdk_python/consensus/topic_id.py (1)
TopicId(21-128)
examples/account/account_allowance_delete_transaction_nft.py (4)
src/hiero_sdk_python/client/client.py (2)
set_operator(149-154)Client(28-255)src/hiero_sdk_python/tokens/nft_id.py (1)
NftId(17-105)src/hiero_sdk_python/account/account_id.py (1)
AccountId(21-198)src/hiero_sdk_python/account/account_allowance_approve_transaction.py (3)
AccountAllowanceApproveTransaction(27-396)approve_token_nft_allowance_all_serials(256-277)delete_token_nft_allowance_all_serials(279-319)
examples/account/account_create_transaction_with_fallback_alias.py (1)
src/hiero_sdk_python/account/account_create_transaction.py (2)
AccountCreateTransaction(27-380)set_key_with_alias(109-135)
examples/topic_info.py (3)
src/hiero_sdk_python/timestamp.py (1)
Timestamp(8-166)tests/unit/topic_info_test.py (1)
topic_info(16-56)src/hiero_sdk_python/consensus/topic_info.py (1)
TopicInfo(21-169)
🪛 Ruff (0.14.10)
examples/client/client.py
77-77: Loop control variable i not used within loop body
Rename unused i to _i
(B007)
examples/logger/logging_example.py
87-87: f-string without any placeholders
Remove extraneous f prefix
(F541)
examples/errors/receipt_status_error.py
64-64: Abstract raise to an inner function
(TRY301)
78-78: Do not catch blind exception: Exception
(BLE001)
examples/consensus/topic_message_submit_chunked_transaction.py
68-68: Consider moving this statement to an else block
(TRY300)
69-69: Do not catch blind exception: Exception
(BLE001)
89-89: Consider moving this statement to an else block
(TRY300)
90-90: Do not catch blind exception: Exception
(BLE001)
118-118: f-string without any placeholders
Remove extraneous f prefix
(F541)
120-120: Cannot reuse outer quote character in f-strings on Python 3.10 (syntax was added in Python 3.12)
(invalid-syntax)
123-123: Do not catch blind exception: Exception
(BLE001)
124-124: Use explicit conversion flag
Replace with conversion flag
(RUF010)
examples/account/account_allowance_approve_transaction_nft.py
236-236: Do not catch blind exception: Exception
(BLE001)
examples/account/account_create_transaction_evm_alias.py
168-168: Do not catch blind exception: Exception
(BLE001)
examples/account/account_create_transaction.py
42-44: Abstract raise to an inner function
(TRY301)
42-44: Create your own exception
(TRY002)
42-44: Avoid specifying long messages outside the exception class
(TRY003)
46-46: Do not catch blind exception: Exception
(BLE001)
47-47: Use explicit conversion flag
Replace with conversion flag
(RUF010)
examples/response_code.py
6-6: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
examples/consensus/topic_message.py
21-21: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
29-29: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
39-39: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
64-64: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
87-87: Boolean-typed positional argument in function definition
(FBT001)
87-87: Boolean default positional argument in function definition
(FBT002)
89-89: Boolean-typed positional argument in function definition
(FBT001)
89-89: Boolean default positional argument in function definition
(FBT002)
examples/consensus/topic_update_transaction.py
88-88: Do not catch blind exception: Exception
(BLE001)
89-89: Use explicit conversion flag
Replace with conversion flag
(RUF010)
examples/account/account_allowance_delete_transaction_nft.py
147-147: Do not catch blind exception: Exception
(BLE001)
172-172: Do not catch blind exception: Exception
(BLE001)
202-202: Do not catch blind exception: Exception
(BLE001)
264-264: f-string without any placeholders
Remove extraneous f prefix
(F541)
271-271: Do not catch blind exception: Exception
(BLE001)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
|
Hi @MrMadHatt, thank you for the clean PR! You did an excellent job with the squashing and signing, the single verified commit looks great. |
|
I’ll need a bit more time to finish reviewing all 64 changed files, but in the meantime feel free to address the bot’s committable suggestions |
exploreriii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MrMadHatt
This is a very extensive PR, thank you! Looks really amazing.
One issue I see - is the issue description was just to black examples/account, i think you have done: black examples
(all of examples, rather than just account).
We have another PR from another person that has done black/file, which means you might be overwriting their change.
I think in this case we could just go ahead with black the entire examples, but as pointed out, its a lot to review which is why we encourage splitting them up.
How would you like to proceed with this? Would you like to close this PR, and just do black for examples/account? Or shall we press forward as the PR is very good
|
I re-read the issue description and noticed it was terribly unclear what to black! In this case, i will proceed by reviewing this PR as it is, many thanks @MrMadHatt |
|
Thank you @exploreriii and @Akshat8510! @exploreriii - Apologies for the scope creep! I was running into some issues running the command for just a single file, and it ended up formatting the entire examples/ directory. I decided to push it for review, but I apologize if I overstepped our original plan and someone else's work. I'm glad to hear the broader update is helpful! @Akshat8510 - I can address the bot's suggestions now, I'll fix these locally and update the PR so we can keep a clean single commit history. Since I've also been assigned to #1301, would you like me to prioritize the bot fixes here first, or should I jump straight to the new issue? Happy to handle it whichever way works best for your review timeline! |
|
Hi @MrMadHatt Please could you prioritize fixing the one example file mentioned here: Once that is done, we can merge this 🥇 |
|
Agreed. @MrMadHatt, let's follow those steps from @exploreriii to get that specific file restored. I'm standing by if you need any help with the git commands or the re-formatting. Looking forward to the final push! 🥇 |
Signed-off-by: Dominiq Barbero <[email protected]>
d06097b to
1a9dada
Compare
|
@exploreriii I have followed the steps: restored account_create_transaction.py from main, applied black formatting to it, and moved the Changelog entry to line 83. @Akshat8510 The history should be clean and ready for the final look! |
|
Hi @MrMadHatt, I see you marked the conversation as resolved, but the security prints are actually still present in file_append_transaction.py |
|
Thanks for catching that @Akshat8510! I've located the prints in examples/file/file_append_transactions.py. To fix this would you prefer I delete those lines entirely, or mask the output? (e.g., print("Operator Key: ") to keep the example flow intact? Once you let me know, I'll push the update right away. |
|
It's best to delete those lines entirely. Printing credentials (even if masked) isn't necessary for the example's functionality and it's generally a safer coding practice to avoid any logic that touches those secrets in the console output. |
|
I'm cognizant this is @MrMadHatt first PR and has followed the issue description These print statements are an existing issue in the example codebase, which has generally been considered fine as its testnet (though you are right we should un-print them), maybe we can create a second good first issue to correct this (and similar instances)? |
Signed-off-by: Dominiq Barbero <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
examples/consensus/topic_message_submit_chunked_transaction.py (1)
118-118: Remove unnecessary f-string prefix.Line 118 uses an f-string prefix without any interpolation placeholders, which is wasteful and demonstrates incorrect f-string usage in an example file that users will copy.
This issue was flagged in the previous review but remains unresolved.
🔎 Proposed fix
- print(f"Message size:", len(BIG_CONTENT), "bytes") + print("Message size:", len(BIG_CONTENT), "bytes")
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
examples/consensus/topic_message_submit_chunked_transaction.pyexamples/file/file_append_transaction.py
🧰 Additional context used
📓 Path-based instructions (1)
examples/**/*
⚙️ CodeRabbit configuration file
examples/**/*: You are acting as a senior maintainer reviewing SDK examples. Your goal is to ensure examples work verbatim for users who copy-paste them.Priority 1 - Correctness:
- Verify transaction lifecycle chain (construction -> freeze_with -> sign -> execute).
- Ensure
freeze_with(client)is called BEFORE signing.- Validate that methods referenced actually exist in the
hiero_sdk_pythoncodebase.- Ensure response validation checks
receipt.statusagainstResponseCodeenums (e.g.,ResponseCode.SUCCESS).Priority 2 - Transaction Lifecycle:
- Check method chaining logic.
- Verify correct signing order (especially for multi-sig).
- Ensure explicit
.execute(client)calls.- Verify response property extraction (e.g., using
.token_id,.account_id,.serial_numbers).- Ensure error handling uses
ResponseCode(receipt.status).namefor clarity.Priority 3 - Naming & Clarity:
- Enforce role-based naming:
operator_id/_key,treasury_account_id/_key,receiver_id/_key.- Use
_idsuffix for AccountId and_keysuffix for PrivateKey variables.- Validate negative examples explicitly check for failure codes (e.g.,
TOKEN_HAS_NO_PAUSE_KEY).- Ensure logical top-to-bottom flow without ambiguity.
Priority 4 - Consistency:
- Verify standard patterns:
def main(),if __name__ == "__main__":,load_dotenv().- IMPORT RULES:
- Accept both top-level imports (e.g.,
from hiero_sdk_python import PrivateKey) and fully qualified imports (e.g.,from hiero_sdk_python.crypto.private_key import PrivateKey).- STRICTLY validate that the import path actually exists in the project structure. Compare against other files in
/examplesor your knowledge of the SDK file tree.- Flag hallucinations immediately (e.g.,
hiero_sdk_python.keysdoes not exist).- Check for
try-exceptblocks withsys.exit(1)for critical failures.Priority 5 - User Experience:
- Ensure comments explain SDK usage patterns (for users,...
Files:
examples/consensus/topic_message_submit_chunked_transaction.pyexamples/file/file_append_transaction.py
🧬 Code graph analysis (2)
examples/consensus/topic_message_submit_chunked_transaction.py (3)
examples/consensus/topic_create_transaction.py (2)
setup_client(24-53)create_topic(56-77)examples/consensus/topic_message_submit_transaction.py (2)
setup_client(25-40)create_topic(43-61)examples/consensus/topic_update_transaction.py (2)
setup_client(25-40)create_topic(43-61)
examples/file/file_append_transaction.py (1)
src/hiero_sdk_python/file/file_append_transaction.py (1)
FileAppendTransaction(37-388)
🪛 Ruff (0.14.10)
examples/consensus/topic_message_submit_chunked_transaction.py
68-68: Consider moving this statement to an else block
(TRY300)
69-69: Do not catch blind exception: Exception
(BLE001)
89-89: Consider moving this statement to an else block
(TRY300)
90-90: Do not catch blind exception: Exception
(BLE001)
118-118: f-string without any placeholders
Remove extraneous f prefix
(F541)
123-123: Do not catch blind exception: Exception
(BLE001)
124-124: Use explicit conversion flag
Replace with conversion flag
(RUF010)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (6)
examples/file/file_append_transaction.py (4)
32-44: ✅ Security concern resolved: debug prints removed.The previous review flagged insecure print statements exposing
OPERATOR_KEYto stdout. These have been removed fromsetup_client(). Users can now safely copy-paste this example without risk of credential leakage.
47-118: ✅ Transaction lifecycle and multi-chunk support correct.All three transaction operations follow the proper chain:
set_*()configurationfreeze_with(client)before signingsign(key)operationexecute(client)submissionMulti-chunk append (lines 93–118) correctly configures
set_chunk_size()andset_max_chunks(). Error handling validatesreceipt.statusagainstResponseCode.SUCCESSand exits on failure.
1-143: ✅ Black formatting applied correctly throughout.All style changes follow Black conventions:
- Imports properly formatted (lines 19–27)
- String quoting normalized to double quotes (lines 29, 39–40)
- Long print statements wrapped for readability (lines 61–63, 85–87, 110–112)
- Whitespace and blank lines adjusted per Black standards
No functional changes; formatting-only modifications are appropriate for this PR.
19-27: All imports inexamples/file/file_append_transaction.py(lines 19-27) are valid and correctly exported fromhiero_sdk_python.Import verification confirms:
Client,Network,PrivateKey,FileCreateTransaction,AccountId,FileAppendTransaction, andResponseCodeall exist in the SDK codebase- All are properly exported via
hiero_sdk_python/__init__.py- Top-level import syntax is correct and idiomatic
examples/consensus/topic_message_submit_chunked_transaction.py (2)
119-121: Excellent fix for the Python 3.10 syntax error!The nested quotes issue has been resolved. Line 120 now correctly uses single quotes
'...'inside the f-string, making this code compatible with Python 3.10+. This addresses the critical syntax error flagged by reviewers.
128-147: Query pattern looks correct.The
fetch_topic_infofunction correctly constructs and executes aTopicInfoQuery. Query operations don't requirefreeze_withor signing, and the patternTopicInfoQuery().set_topic_id(...).execute(client)follows SDK conventions.Note: This depends on the
TopicInfoQueryimport being valid (addressed in separate comment).
|
Actually, @MrMadHatt has already been a superstar and handled both the Python 3.10 syntax fix and the security prints in his latest commit! |
|
Since those critical items are now cleared and the formatting is consistent, I'm completely satisfied with this PR. I agree that any further 'consistency' fixes (like the ones the bot is suggesting now regarding explicit signing) should be handled in a separate issue to keep this one focused. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first contribution by @MrMadHatt!
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1320 +/- ##
=======================================
Coverage 92.29% 92.29%
=======================================
Files 139 139
Lines 8515 8515
=======================================
Hits 7859 7859
Misses 656 656 🚀 New features to boost your workflow:
|
exploreriii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much @MrMadHatt for this massive formatting improvement and taking the time to get it just right!
|
Thank you so much @Akshat8510 and @exploreriii! I really appreciate the mentorship and the kind words. Extra thanks for helping me navigate through those 14 commits and the hit history hurdle the other day! Getting that sorted was a huge learning moment for me. I'm glad the final fixes for the Python 3.10 syntax and security prints hit the mark. Looking forward to the next one! |
|
Really happy to hear that you are feeling good about overcoming those hurdles!! If you are up for the next level up, we have a couple of beginner friendly issues here: |
Description:
Related issue(s):
Fixes #1299
Fixes #1301
Fixes # This PR applies black formatting to the examples/ directory
Notes for reviewer:
This PR strictly covers code style formatting using black. All 14 original commits have been squashed into a single verified commit. GPG and DCO signatures have been applied to meet the SDK contribution guidelines.
Checklist