Skip to content

Commit ff85a58

Browse files
BYKclaude
andcommitted
fix: Remove from __future__ import annotations for Python 3.6 compat
Python 3.6 doesn't support PEP 563 (from __future__ import annotations). Use string-quoted annotations instead, matching the convention used in the rest of the SDK. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5ea3aac commit ff85a58

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

sentry_sdk/worker.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from abc import ABC, abstractmethod
42
import asyncio
53
import os
@@ -49,7 +47,7 @@ def kill(self) -> None:
4947
pass
5048

5149
def flush(
52-
self, timeout: float, callback: Optional[Callable[[int, float], Any]] = None
50+
self, timeout: float, callback: "Optional[Callable[[int, float], Any]]" = None
5351
) -> None:
5452
"""
5553
Flush the worker.
@@ -70,7 +68,7 @@ def full(self) -> bool:
7068
pass
7169

7270
@abstractmethod
73-
def submit(self, callback: Callable[[], Any]) -> bool:
71+
def submit(self, callback: "Callable[[], Any]") -> bool:
7472
"""
7573
Schedule a callback to be executed by the worker.
7674
@@ -81,10 +79,10 @@ def submit(self, callback: Callable[[], Any]) -> bool:
8179

8280
class BackgroundWorker(Worker):
8381
def __init__(self, queue_size: int = DEFAULT_QUEUE_SIZE) -> None:
84-
self._queue: Queue = Queue(queue_size)
82+
self._queue: "Queue" = Queue(queue_size)
8583
self._lock = threading.Lock()
86-
self._thread: Optional[threading.Thread] = None
87-
self._thread_for_pid: Optional[int] = None
84+
self._thread: "Optional[threading.Thread]" = None
85+
self._thread_for_pid: "Optional[int]" = None
8886

8987
@property
9088
def is_alive(self) -> bool:
@@ -147,7 +145,7 @@ def kill(self) -> None:
147145
self._thread = None
148146
self._thread_for_pid = None
149147

150-
def flush(self, timeout: float, callback: Optional[Any] = None) -> None:
148+
def flush(self, timeout: float, callback: "Optional[Any]" = None) -> None:
151149
logger.debug("background worker got flush request")
152150
with self._lock:
153151
if self.is_alive and timeout > 0.0:
@@ -157,7 +155,7 @@ def flush(self, timeout: float, callback: Optional[Any] = None) -> None:
157155
def full(self) -> bool:
158156
return self._queue.full()
159157

160-
def _wait_flush(self, timeout: float, callback: Optional[Any]) -> None:
158+
def _wait_flush(self, timeout: float, callback: "Optional[Any]") -> None:
161159
initial_timeout = min(0.1, timeout)
162160
if not self._timed_queue_join(initial_timeout):
163161
pending = self._queue.qsize() + 1
@@ -169,7 +167,7 @@ def _wait_flush(self, timeout: float, callback: Optional[Any]) -> None:
169167
pending = self._queue.qsize() + 1
170168
logger.error("flush timed out, dropped %s events", pending)
171169

172-
def submit(self, callback: Callable[[], Any]) -> bool:
170+
def submit(self, callback: "Callable[[], Any]") -> bool:
173171
self._ensure_thread()
174172
try:
175173
self._queue.put_nowait(callback)
@@ -194,14 +192,14 @@ def _target(self) -> None:
194192

195193
class AsyncWorker(Worker):
196194
def __init__(self, queue_size: int = DEFAULT_QUEUE_SIZE) -> None:
197-
self._queue: Optional[asyncio.Queue[Any]] = None
195+
self._queue: "Optional[asyncio.Queue[Any]]" = None
198196
self._queue_size = queue_size
199-
self._task: Optional[asyncio.Task[None]] = None
197+
self._task: "Optional[asyncio.Task[None]]" = None
200198
# Event loop needs to remain in the same process
201-
self._task_for_pid: Optional[int] = None
202-
self._loop: Optional[asyncio.AbstractEventLoop] = None
199+
self._task_for_pid: "Optional[int]" = None
200+
self._loop: "Optional[asyncio.AbstractEventLoop]" = None
203201
# Track active callback tasks so they have a strong reference and can be cancelled on kill
204-
self._active_tasks: set[asyncio.Task[None]] = set()
202+
self._active_tasks: "set[asyncio.Task[None]]" = set()
205203

206204
@property
207205
def is_alive(self) -> bool:
@@ -255,7 +253,9 @@ def _ensure_task(self) -> None:
255253
if not self.is_alive:
256254
self.start()
257255

258-
async def _wait_flush(self, timeout: float, callback: Optional[Any] = None) -> None:
256+
async def _wait_flush(
257+
self, timeout: float, callback: "Optional[Any]" = None
258+
) -> None:
259259
if not self._loop or not self._loop.is_running() or self._queue is None:
260260
return
261261

@@ -278,14 +278,14 @@ async def _wait_flush(self, timeout: float, callback: Optional[Any] = None) -> N
278278
logger.error("flush timed out, dropped %s events", pending)
279279

280280
def flush( # type: ignore[override]
281-
self, timeout: float, callback: Optional[Any] = None
282-
) -> Optional[asyncio.Task[None]]:
281+
self, timeout: float, callback: "Optional[Any]" = None
282+
) -> "Optional[asyncio.Task[None]]":
283283
if self.is_alive and timeout > 0.0 and self._loop and self._loop.is_running():
284284
with mark_sentry_task_internal():
285285
return self._loop.create_task(self._wait_flush(timeout, callback))
286286
return None
287287

288-
def submit(self, callback: Callable[[], Any]) -> bool:
288+
def submit(self, callback: "Callable[[], Any]") -> bool:
289289
self._ensure_task()
290290
if self._queue is None:
291291
return False
@@ -313,11 +313,11 @@ async def _target(self) -> None:
313313
# Yield to let the event loop run other tasks
314314
await asyncio.sleep(0)
315315

316-
async def _process_callback(self, callback: Callable[[], Any]) -> None:
316+
async def _process_callback(self, callback: "Callable[[], Any]") -> None:
317317
# Callback is an async coroutine, need to await it
318318
await callback()
319319

320-
def _on_task_complete(self, task: asyncio.Task[None]) -> None:
320+
def _on_task_complete(self, task: "asyncio.Task[None]") -> None:
321321
try:
322322
task.result()
323323
except asyncio.CancelledError:

0 commit comments

Comments
 (0)