feat: add autoflake pre-commit hook to remove unused imports#1528
feat: add autoflake pre-commit hook to remove unused imports#1528cristiam86 wants to merge 4 commits intomainfrom
Conversation
- Added autoflake v2.3.1 to .pre-commit-config.yaml to automatically remove unused imports on commit, running before black for proper formatting - Autoflake cleaned up 100+ unused imports across 75 Python files - All DB/SQLAlchemy tests pass (60/60)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an autoflake pre-commit hook and removes numerous unused imports and a few trivial Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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.
🧹 Nitpick comments (2)
tests/db-sqlalchemy/transactions_processor_test.py (1)
202-206: Remove redundantpassstatement.The
passat line 203 is a no-op leftover from replacing the unusedimport timestatement. Since the function body contains actual code, thispassserves no purpose and can be removed.🧹 Proposed fix
def test_get_highest_timestamp(transactions_processor: TransactionsProcessor): - pass - # Initially should return 0 when no transactions exist assert transactions_processor.get_highest_timestamp() == 0🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/db-sqlalchemy/transactions_processor_test.py` around lines 202 - 206, Remove the redundant no-op "pass" from the test function test_get_highest_timestamp so the function body only contains the actual assertion; locate the test_get_highest_timestamp definition in the tests and delete the solitary pass line while leaving the assertion that calls TransactionsProcessor.get_highest_timestamp() intact.backend/node/genvm/base.py (1)
198-198: Remove orphanedpassstatement.The
passstatement is a no-op that appears to be leftover from removing the logging setup. It serves no purpose since the code continues immediately to line 200. Consider removing it for cleaner code.🧹 Suggested cleanup
elif res.result_kind == ResultCode.INTERNAL_ERROR: - pass - error_ctx = None🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/node/genvm/base.py` at line 198, Remove the orphaned no-op "pass" statement that was left behind in the function/method body (the stray pass at the top of the block) since it serves no purpose and the subsequent code executes immediately; simply delete that pass, verify indentation and surrounding logic remain correct (no placeholder needed), and run tests/lint to ensure no behavioral or formatting regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/node/genvm/base.py`:
- Line 198: Remove the orphaned no-op "pass" statement that was left behind in
the function/method body (the stray pass at the top of the block) since it
serves no purpose and the subsequent code executes immediately; simply delete
that pass, verify indentation and surrounding logic remain correct (no
placeholder needed), and run tests/lint to ensure no behavioral or formatting
regressions.
In `@tests/db-sqlalchemy/transactions_processor_test.py`:
- Around line 202-206: Remove the redundant no-op "pass" from the test function
test_get_highest_timestamp so the function body only contains the actual
assertion; locate the test_get_highest_timestamp definition in the tests and
delete the solitary pass line while leaving the assertion that calls
TransactionsProcessor.get_highest_timestamp() intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f75e4773-fa06-4360-afe1-819d82bf934e
📒 Files selected for processing (76)
.pre-commit-config.yamlasgi.pybackend/consensus/base.pybackend/consensus/monitoring.pybackend/consensus/worker.pybackend/consensus/worker_service.pybackend/database_handler/chain_snapshot.pybackend/database_handler/contract_processor.pybackend/database_handler/migration/versions/3bc34e44eb72_add_providers_unique_constraint.pybackend/database_handler/migration/versions/67943badcbe9_add_activated_status.pybackend/database_handler/migration/versions/6fd3e2cea05b_add_default_to_llm_providers.pybackend/database_handler/migration/versions/99015c5b5b78_add_snapshot_table.pybackend/database_handler/migration/versions/ab256b41602a_remove_invalid_models.pybackend/database_handler/migration/versions/db38e78684a8_add_providers_table.pybackend/database_handler/transactions_processor.pybackend/domain/types.pybackend/node/base.pybackend/node/genvm/base.pybackend/node/genvm/origin/base_host.pybackend/node/genvm/origin/host_fns.pybackend/protocol_rpc/app_lifespan.pybackend/protocol_rpc/broadcast.pybackend/protocol_rpc/calls_intercept/__init__.pybackend/protocol_rpc/contract_linter.pybackend/protocol_rpc/endpoints.pybackend/protocol_rpc/explorer/queries.pybackend/protocol_rpc/fastapi_endpoint_generator.pybackend/protocol_rpc/fastapi_rpc_handler.pybackend/protocol_rpc/fastapi_server.pybackend/protocol_rpc/message_handler/fastapi_handler.pybackend/protocol_rpc/message_handler/worker_handler.pybackend/protocol_rpc/rpc_endpoint_manager.pybackend/protocol_rpc/transactions_parser.pybackend/protocol_rpc/validators_init.pybackend/rollup/consensus_service.pybackend/validators/__init__.pyscripts/update_error_transactions_metrics.pytests/common/request.pytests/common/transactions.pytests/db-sqlalchemy/accounts_manager_test.pytests/db-sqlalchemy/snapshot_manager_test.pytests/db-sqlalchemy/transactions_processor_test.pytests/direct/test_genvm_smoke_direct.pytests/integration/icontracts/contracts/intelligent_oracle.pytests/integration/icontracts/tests/test_multi_file_contract.pytests/load/deploy_contract/test_wizard_of_coin.pytests/load/deploy_contract/wizard_deploy.pytests/load/deploy_contract/wizard_deploy_and_read.pytests/load/script_archive_unused/analyze_transactions.pytests/load/script_archive_unused/deploy_contract_example.pytests/load/script_archive_unused/deploy_wizard_of_coin.pytests/load/script_archive_unused/generate_correct_deployment_tx.pytests/load/script_archive_unused/generate_deployment_tx_ui_format.pytests/load/script_archive_unused/generate_raw_transaction.pytests/load/script_archive_unused/generate_raw_transaction_fixed.pytests/load/script_archive_unused/generate_ui_compatible_tx.pytests/test_linter_endpoint.pytests/unit/consensus/test_decisions_accepted.pytests/unit/consensus/test_decisions_caller_helpers.pytests/unit/consensus/test_decisions_pending_proposing_committing.pytests/unit/consensus/test_decisions_terminal.pytests/unit/consensus/test_effect_executor.pytests/unit/consensus/test_effects.pytests/unit/consensus/test_helpers.pytests/unit/test_contract_not_found_handling.pytests/unit/test_create_nodes.pytests/unit/test_error_codes.pytests/unit/test_execution_mode.pytests/unit/test_fallback_validator_model_host_data.pytests/unit/test_genvm_retry.pytests/unit/test_genvm_retry_integration.pytests/unit/test_node_execution_time.pytests/unit/test_rate_limiter.pytests/unit/test_types.pytests/unit/test_worker_health_degradation.pyuvicorn_config.py
💤 Files with no reviewable changes (57)
- tests/unit/consensus/test_decisions_terminal.py
- backend/protocol_rpc/message_handler/worker_handler.py
- tests/unit/test_create_nodes.py
- tests/db-sqlalchemy/accounts_manager_test.py
- backend/node/base.py
- backend/database_handler/transactions_processor.py
- tests/unit/test_types.py
- backend/consensus/worker.py
- tests/load/deploy_contract/test_wizard_of_coin.py
- backend/node/genvm/origin/base_host.py
- tests/integration/icontracts/tests/test_multi_file_contract.py
- tests/load/script_archive_unused/deploy_wizard_of_coin.py
- backend/protocol_rpc/message_handler/fastapi_handler.py
- backend/validators/init.py
- tests/load/script_archive_unused/deploy_contract_example.py
- tests/test_linter_endpoint.py
- tests/load/script_archive_unused/generate_deployment_tx_ui_format.py
- backend/protocol_rpc/broadcast.py
- tests/unit/test_fallback_validator_model_host_data.py
- tests/load/script_archive_unused/generate_ui_compatible_tx.py
- tests/common/transactions.py
- tests/load/script_archive_unused/generate_raw_transaction_fixed.py
- backend/database_handler/contract_processor.py
- tests/unit/test_node_execution_time.py
- backend/protocol_rpc/endpoints.py
- backend/protocol_rpc/fastapi_server.py
- tests/unit/consensus/test_decisions_pending_proposing_committing.py
- backend/database_handler/migration/versions/3bc34e44eb72_add_providers_unique_constraint.py
- tests/unit/consensus/test_effects.py
- tests/unit/test_error_codes.py
- tests/unit/consensus/test_helpers.py
- tests/load/script_archive_unused/generate_correct_deployment_tx.py
- tests/unit/consensus/test_decisions_accepted.py
- tests/unit/test_worker_health_degradation.py
- tests/load/script_archive_unused/analyze_transactions.py
- backend/database_handler/migration/versions/ab256b41602a_remove_invalid_models.py
- backend/database_handler/migration/versions/6fd3e2cea05b_add_default_to_llm_providers.py
- tests/unit/consensus/test_decisions_caller_helpers.py
- backend/domain/types.py
- backend/protocol_rpc/fastapi_rpc_handler.py
- tests/db-sqlalchemy/snapshot_manager_test.py
- backend/rollup/consensus_service.py
- backend/database_handler/migration/versions/67943badcbe9_add_activated_status.py
- tests/direct/test_genvm_smoke_direct.py
- backend/consensus/base.py
- backend/protocol_rpc/app_lifespan.py
- tests/unit/test_genvm_retry.py
- tests/load/deploy_contract/wizard_deploy_and_read.py
- tests/load/script_archive_unused/generate_raw_transaction.py
- backend/protocol_rpc/rpc_endpoint_manager.py
- backend/database_handler/migration/versions/99015c5b5b78_add_snapshot_table.py
- backend/database_handler/migration/versions/db38e78684a8_add_providers_table.py
- tests/load/deploy_contract/wizard_deploy.py
- backend/consensus/worker_service.py
- uvicorn_config.py
- asgi.py
- backend/protocol_rpc/calls_intercept/init.py
- Restored `from backend.protocol_rpc import rpc_methods` in app_lifespan.py with noqa comment — this is a side-effect import that registers all RPC methods via decorators - Removed remaining unused imports from backend/consensus/base.py that were missed in the initial autoflake run
Fixes #DXP-645
What
.pre-commit-config.yamlto automatically remove unused imports during commitsWhy
Unused imports create code smell and increase maintenance burden. Automating their removal keeps the codebase clean without manual effort.
Testing done
Decisions made
Checks
Summary by CodeRabbit