Copilot commented on code in PR #1290:
URL: 
https://github.com/apache/cassandra-python-driver/pull/1290#discussion_r3150773277


##########
cassandra/cluster.py:
##########
@@ -1424,26 +1424,26 @@ def _create_thread_pool_executor(self, **kwargs):
         :return: A ThreadPoolExecutor instance.
         """
         tpe_class = ThreadPoolExecutor
-        if sys.version_info[0] >= 3 and sys.version_info[1] >= 7:
-            try:
-                from cassandra.io.eventletreactor import EventletConnection
-                is_eventlet = issubclass(self.connection_class, 
EventletConnection)
-            except:
-                # Eventlet is not available or can't be detected
-                return tpe_class(**kwargs)
 
-            if is_eventlet:
-                try:
-                    from futurist import GreenThreadPoolExecutor
-                    tpe_class = GreenThreadPoolExecutor
-                except ImportError:
-                    # futurist is not available
-                    raise ImportError(
-                        ("Python 3.7+ and Eventlet cause the 
`concurrent.futures.ThreadPoolExecutor` "
-                         "to hang indefinitely. If you want to use the 
Eventlet reactor, you "
-                         "need to install the `futurist` package to allow the 
driver to use "
-                         "the GreenThreadPoolExecutor. See 
https://github.com/eventlet/eventlet/issues/508 "
-                         "for more details."))
+        try:
+            from cassandra.io.eventletreactor import EventletConnection
+            is_eventlet = issubclass(self.connection_class, EventletConnection)
+        except:
+            # Eventlet is not available or can't be detected
+            return tpe_class(**kwargs)
+
+        if is_eventlet:
+            try:
+                from futurist import GreenThreadPoolExecutor
+                tpe_class = GreenThreadPoolExecutor
+            except ImportError:
+                # futurist is not available
+                raise ImportError(
+                    ("Python 3.7+ and Eventlet cause the 
`concurrent.futures.ThreadPoolExecutor` "
+                     "to hang indefinitely. If you want to use the Eventlet 
reactor, you "
+                     "need to install the `futurist` package to allow the 
driver to use "
+                     "the GreenThreadPoolExecutor. See 
https://github.com/eventlet/eventlet/issues/508 "
+                     "for more details."))

Review Comment:
   When `from futurist import GreenThreadPoolExecutor` fails, the custom 
`ImportError` raised here replaces the original import exception, which can 
make troubleshooting harder (e.g., partial/old futurist install). Capture the 
exception (`except ImportError as e`) and chain it (`raise ImportError(...) 
from e`) so the root cause is preserved while still providing the actionable 
message.
   ```suggestion
               except ImportError as e:
                   # futurist is not available
                   raise ImportError(
                       ("Python 3.7+ and Eventlet cause the 
`concurrent.futures.ThreadPoolExecutor` "
                        "to hang indefinitely. If you want to use the Eventlet 
reactor, you "
                        "need to install the `futurist` package to allow the 
driver to use "
                        "the GreenThreadPoolExecutor. See 
https://github.com/eventlet/eventlet/issues/508 "
                        "for more details.")) from e
   ```



##########
cassandra/cluster.py:
##########
@@ -1424,26 +1424,26 @@ def _create_thread_pool_executor(self, **kwargs):
         :return: A ThreadPoolExecutor instance.
         """
         tpe_class = ThreadPoolExecutor
-        if sys.version_info[0] >= 3 and sys.version_info[1] >= 7:
-            try:
-                from cassandra.io.eventletreactor import EventletConnection
-                is_eventlet = issubclass(self.connection_class, 
EventletConnection)
-            except:
-                # Eventlet is not available or can't be detected
-                return tpe_class(**kwargs)
 
-            if is_eventlet:
-                try:
-                    from futurist import GreenThreadPoolExecutor
-                    tpe_class = GreenThreadPoolExecutor
-                except ImportError:
-                    # futurist is not available
-                    raise ImportError(
-                        ("Python 3.7+ and Eventlet cause the 
`concurrent.futures.ThreadPoolExecutor` "
-                         "to hang indefinitely. If you want to use the 
Eventlet reactor, you "
-                         "need to install the `futurist` package to allow the 
driver to use "
-                         "the GreenThreadPoolExecutor. See 
https://github.com/eventlet/eventlet/issues/508 "
-                         "for more details."))
+        try:
+            from cassandra.io.eventletreactor import EventletConnection
+            is_eventlet = issubclass(self.connection_class, EventletConnection)
+        except:

Review Comment:
   Avoid a bare `except:` here. It will also swallow 
`KeyboardInterrupt`/`SystemExit` and can mask real failures inside 
`cassandra.io.eventletreactor` (not just “eventlet not available”). Prefer 
catching the specific exceptions you expect (e.g., `ImportError` / 
`AttributeError`, matching the module-level import guard) and/or reuse the 
already-defined module-level `EventletConnection` optional import instead of 
re-importing and blanket-catching.
   ```suggestion
           except (ImportError, AttributeError, TypeError):
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to