Skip to content

Commit aaae195

Browse files
committed
ref(transport): Fix import checking
GH-4582
1 parent 10d85f6 commit aaae195

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

sentry_sdk/transport.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818

1919
try:
2020
import httpcore
21+
except ImportError:
22+
httpcore = None # type: ignore
23+
24+
try:
2125
import h2 # noqa: F401
2226

23-
HTTP2_ENABLED = True
27+
HTTP2_ENABLED = httpcore is not None
2428
except ImportError:
2529
HTTP2_ENABLED = False
26-
httpcore = None # type: ignore
2730

2831
try:
29-
import httpcore # noqa: F401
30-
import anyio # noqa: F401
31-
32-
ASYNC_TRANSPORT_ENABLED = True
32+
ASYNC_TRANSPORT_ENABLED = httpcore is not None
3333
except ImportError:
3434
ASYNC_TRANSPORT_ENABLED = False
3535

@@ -238,7 +238,11 @@ def _create_worker(self, options: dict[str, Any]) -> Worker:
238238
async_enabled = options.get("_experiments", {}).get("transport_async", False)
239239
try:
240240
asyncio.get_running_loop()
241-
worker_cls = AsyncWorker if async_enabled else BackgroundWorker
241+
worker_cls = (
242+
AsyncWorker
243+
if async_enabled and ASYNC_TRANSPORT_ENABLED
244+
else BackgroundWorker
245+
)
242246
except RuntimeError:
243247
worker_cls = BackgroundWorker
244248
return worker_cls(queue_size=options["transport_queue_size"])

0 commit comments

Comments
 (0)