From 322858e0f6a3d649f51507fa4b71995f92d03f00 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Thu, 29 Jan 2026 16:44:57 -0400 Subject: [PATCH] Remove Python 2 compatibility code The driver requires Python 3.10+ so these compatibility shims are no longer needed: - Remove try/except for Queue vs queue (use queue directly) - Remove try/except for __builtin__ vs builtins (use builtins directly) - Remove try/except for thread vs _thread (use _thread directly) - Remove try/except for futures vs concurrent.futures (use concurrent.futures directly) - Remove try/except for unittest2 vs unittest (use unittest directly) - Replace deprecated imp.reload with importlib.reload --- tests/integration/long/test_large_data.py | 5 +---- tests/integration/standard/test_shard_aware.py | 12 +++--------- tests/integration/standard/test_use_keyspace.py | 5 +---- tests/unit/io/eventlet_utils.py | 14 ++++---------- tests/unit/test_protocol_features.py | 5 +---- tests/unit/test_shard_aware.py | 5 +---- 6 files changed, 11 insertions(+), 35 deletions(-) diff --git a/tests/integration/long/test_large_data.py b/tests/integration/long/test_large_data.py index a79a6da4f5..0a1b368bf0 100644 --- a/tests/integration/long/test_large_data.py +++ b/tests/integration/long/test_large_data.py @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from Queue import Queue, Empty -except ImportError: - from queue import Queue, Empty # noqa +from queue import Queue, Empty from struct import pack import logging, sys, traceback, time diff --git a/tests/integration/standard/test_shard_aware.py b/tests/integration/standard/test_shard_aware.py index 215c69c3b4..48d1aa3609 100644 --- a/tests/integration/standard/test_shard_aware.py +++ b/tests/integration/standard/test_shard_aware.py @@ -17,15 +17,9 @@ from subprocess import run import logging -try: - from concurrent.futures import ThreadPoolExecutor, as_completed -except ImportError: - from futures import ThreadPoolExecutor, as_completed # noqa - -try: - import unittest2 as unittest -except ImportError: - import unittest # noqa +from concurrent.futures import ThreadPoolExecutor, as_completed + +import unittest import pytest from cassandra.cluster import Cluster diff --git a/tests/integration/standard/test_use_keyspace.py b/tests/integration/standard/test_use_keyspace.py index 72ddbf9ef4..25e954b956 100644 --- a/tests/integration/standard/test_use_keyspace.py +++ b/tests/integration/standard/test_use_keyspace.py @@ -2,10 +2,7 @@ import time import logging -try: - import unittest2 as unittest -except ImportError: - import unittest # noqa +import unittest from unittest.mock import patch diff --git a/tests/unit/io/eventlet_utils.py b/tests/unit/io/eventlet_utils.py index 785856be20..2a5a8c78d0 100644 --- a/tests/unit/io/eventlet_utils.py +++ b/tests/unit/io/eventlet_utils.py @@ -16,21 +16,15 @@ import os import select import socket -try: - import thread - import Queue - import __builtin__ - #For python3 compatibility -except ImportError: - import _thread as thread - import queue as Queue - import builtins as __builtin__ +import _thread as thread +import queue as Queue +import builtins as __builtin__ import threading import ssl import time import eventlet -from imp import reload +from importlib import reload def eventlet_un_patch_all(): """ diff --git a/tests/unit/test_protocol_features.py b/tests/unit/test_protocol_features.py index 89b568ea68..895c384f7e 100644 --- a/tests/unit/test_protocol_features.py +++ b/tests/unit/test_protocol_features.py @@ -1,7 +1,4 @@ -try: - import unittest2 as unittest -except ImportError: - import unittest # noqa +import unittest import logging diff --git a/tests/unit/test_shard_aware.py b/tests/unit/test_shard_aware.py index 0d13a243ab..e7d26ae207 100644 --- a/tests/unit/test_shard_aware.py +++ b/tests/unit/test_shard_aware.py @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - import unittest2 as unittest -except ImportError: - import unittest # noqa +import unittest import logging from unittest.mock import MagicMock