Skip to content

Remove unused imports#895

Open
mykaul wants to merge 2 commits into
scylladb:masterfrom
mykaul:remove-unused-imports
Open

Remove unused imports#895
mykaul wants to merge 2 commits into
scylladb:masterfrom
mykaul:remove-unused-imports

Conversation

@mykaul
Copy link
Copy Markdown

@mykaul mykaul commented Jun 3, 2026

Summary

Removes unused imports across the driver and the test suite, split into two commits:

  • Remove unused imports from driver codecassandra/ package
  • Remove unused imports from teststests/

Detected with ruff --select F401.

Notes on preserved imports

The following "unused" imports were intentionally kept, because they are not truly unused:

  • Dynamically resolved: cassandra/protocol.py resolves 21 cqltype classes by name via globals()[name] to build ResultMessage.type_codes. Removing them breaks import with KeyError. Kept with a # noqa: F401 block and an explanatory comment.
  • Public re-export: cassandra/connection.py re-exports ShardingInfo (consumed via from cassandra.connection import ShardingInfo, e.g. tests/unit/test_shard_aware.py). Kept with # noqa: F401.
  • Availability probes: imports inside try/except ImportError used to detect optional dependencies (kerberos, numpy, cryptography, gremlin_python, ccmlib.common, make_recv_results_rows).
  • Package re-export hubs: genuine public re-exports in cassandra/datastax/graph/__init__.py.

Testing

  • Rebuilt the Cython extensions (build_ext --inplace / uv sync --reinstall-package scylla-driver) so the edited .py sources are actually exercised.
  • Unit suite: 714 passed, 37 skipped (2 pre-existing test_cluster.py failures unrelated to this change; reactor-timer tests excluded as they hang in the sandbox).
  • All 45 modified test files byte-compile cleanly.

Note: integration tests were not run here (require a live CCM/Scylla environment).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bdadfdd9-afc9-457b-ae8d-5650a2a86089

📥 Commits

Reviewing files that changed from the base of the PR and between 037118e and e5c83c3.

📒 Files selected for processing (57)
  • cassandra/cluster.py
  • cassandra/concurrent.py
  • cassandra/connection.py
  • cassandra/cqlengine/connection.py
  • cassandra/cqlengine/query.py
  • cassandra/cqltypes.py
  • cassandra/datastax/cloud/__init__.py
  • cassandra/encoder.py
  • cassandra/io/asyncioreactor.py
  • cassandra/io/asyncorereactor.py
  • cassandra/pool.py
  • cassandra/protocol.py
  • tests/integration/cqlengine/__init__.py
  • tests/integration/cqlengine/base.py
  • tests/integration/cqlengine/connections/test_connection.py
  • tests/integration/cqlengine/management/test_management.py
  • tests/integration/cqlengine/model/test_model.py
  • tests/integration/cqlengine/model/test_model_io.py
  • tests/integration/cqlengine/query/test_named.py
  • tests/integration/cqlengine/statements/test_select_statement.py
  • tests/integration/cqlengine/statements/test_update_statement.py
  • tests/integration/cqlengine/test_connections.py
  • tests/integration/cqlengine/test_ifexists.py
  • tests/integration/cqlengine/test_ttl.py
  • tests/integration/long/test_large_data.py
  • tests/integration/simulacron/__init__.py
  • tests/integration/simulacron/test_cluster.py
  • tests/integration/simulacron/test_connection.py
  • tests/integration/simulacron/test_empty_column.py
  • tests/integration/simulacron/test_endpoint.py
  • tests/integration/simulacron/utils.py
  • tests/integration/standard/conftest.py
  • tests/integration/standard/test_cluster.py
  • tests/integration/standard/test_concurrent.py
  • tests/integration/standard/test_concurrent_schema_change_and_node_kill.py
  • tests/integration/standard/test_custom_cluster.py
  • tests/integration/standard/test_custom_payload.py
  • tests/integration/standard/test_custom_protocol_handler.py
  • tests/integration/standard/test_metadata.py
  • tests/integration/standard/test_policies.py
  • tests/integration/standard/test_query.py
  • tests/integration/standard/test_query_paging.py
  • tests/integration/standard/test_shard_aware.py
  • tests/integration/standard/test_single_interface.py
  • tests/integration/standard/test_types.py
  • tests/integration/upgrade/__init__.py
  • tests/integration/upgrade/test_upgrade.py
  • tests/stress_tests/test_load.py
  • tests/unit/advanced/test_graph.py
  • tests/unit/advanced/test_insights.py
  • tests/unit/advanced/test_metadata.py
  • tests/unit/io/test_asyncorereactor.py
  • tests/unit/io/test_twistedreactor.py
  • tests/unit/test_endpoints.py
  • tests/unit/test_host_connection_pool.py
  • tests/unit/test_marshalling.py
  • tests/unit/test_protocol.py
💤 Files with no reviewable changes (26)
  • tests/integration/standard/test_query_paging.py
  • tests/integration/standard/test_concurrent_schema_change_and_node_kill.py
  • tests/integration/cqlengine/base.py
  • tests/integration/cqlengine/model/test_model_io.py
  • tests/integration/cqlengine/init.py
  • tests/integration/upgrade/test_upgrade.py
  • cassandra/datastax/cloud/init.py
  • tests/stress_tests/test_load.py
  • tests/integration/simulacron/utils.py
  • tests/unit/io/test_twistedreactor.py
  • cassandra/concurrent.py
  • tests/integration/simulacron/test_endpoint.py
  • tests/unit/io/test_asyncorereactor.py
  • tests/integration/simulacron/test_connection.py
  • cassandra/pool.py
  • tests/integration/simulacron/init.py
  • tests/integration/standard/test_concurrent.py
  • tests/integration/cqlengine/model/test_model.py
  • tests/unit/test_host_connection_pool.py
  • tests/unit/test_protocol.py
  • tests/integration/simulacron/test_empty_column.py
  • tests/integration/standard/conftest.py
  • cassandra/encoder.py
  • tests/integration/cqlengine/management/test_management.py
  • tests/unit/test_marshalling.py
  • cassandra/io/asyncorereactor.py

📝 Walkthrough

Walkthrough

This pull request performs a comprehensive cleanup of unused imports across the entire Cassandra Python driver codebase and test suite. Changes include removing unused module imports (sys, unittest, logging, platform, time, socket, uuid), removing unused imports from module dependency lists (InvalidRequest, ConsistencyLevel, BatchStatement, various test utilities), and adding noqa annotations to intentional module-level re-exports. The cassandra/protocol.py file receives special attention with added documentation explaining that imports marked noqa are required for dynamic resolution in ResultMessage.type_codes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing unused imports across the codebase.
Description check ✅ Passed The description comprehensively covers the changes, notes intentionally preserved imports, testing performed, and CI results, though it differs from the template structure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@mykaul
Copy link
Copy Markdown
Author

mykaul commented Jun 3, 2026

CI summary

All checks relevant to this change are green. The matrix result:

  • build, source-dist, wheels, snyk: pass
  • test asyncio / asyncore / libev across Python 3.11–3.14 (and asyncio 3.14t): pass
  • test libev (3.14t): 1 failing integration test (see below)
  • jira-sync: fail — expected org automation that requires a Jira key; unrelated to code

Why test libev (3.14t) failed (not caused by this PR)

FAILED tests/integration/standard/test_client_routes.py::TestPrivateLinkConnectivity::test_queries_succeed_through_proxy
       - AttributeError: 'NoneType' object has no attribute 'v'
1 failed, 934 passed, 73 skipped, 12 xfailed

This PR only removes unused imports. The failure is unrelated:

  1. A missing import would surface as NameError/ImportError, not an AttributeError deep inside PrivateLink proxy logic.
  2. The same test passed on test asyncio (3.14t) and on every other interpreter/reactor combination — it failed only on the libev free-threaded flavor, which points to a flake / 3.14t-specific environment issue rather than a logic regression.
  3. The trailing RuntimeError: cannot schedule new futures after interpreter shutdown messages are teardown noise typical of free-threaded (3.14t) shutdown, not a test assertion failure.

No import touched by this PR is referenced by test_client_routes.py.

@mykaul mykaul marked this pull request as ready for review June 3, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant