Skip to content

Commit 9b6a718

Browse files
ref(transport): Improve event data category typing
Done to more clearly define event data categories, in preparation for #3229.
1 parent 70b12c3 commit 9b6a718

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

sentry_sdk/transport.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
from urllib3.poolmanager import PoolManager
3535
from urllib3.poolmanager import ProxyManager
3636

37-
from sentry_sdk._types import Event
38-
39-
DataCategory = Optional[str]
37+
from sentry_sdk._types import Event, EventDataCategory
4038

4139
KEEP_ALIVE_SOCKET_OPTIONS = []
4240
for option in [
@@ -133,7 +131,7 @@ def kill(self):
133131
def record_lost_event(
134132
self,
135133
reason, # type: str
136-
data_category=None, # type: Optional[str]
134+
data_category=None, # type: Optional[EventDataCategory]
137135
item=None, # type: Optional[Item]
138136
):
139137
# type: (...) -> None
@@ -155,7 +153,7 @@ def __del__(self):
155153

156154

157155
def _parse_rate_limits(header, now=None):
158-
# type: (Any, Optional[datetime]) -> Iterable[Tuple[DataCategory, datetime]]
156+
# type: (Any, Optional[datetime]) -> Iterable[Tuple[Optional[EventDataCategory], datetime]]
159157
if now is None:
160158
now = datetime.now(timezone.utc)
161159

@@ -195,11 +193,11 @@ def __init__(
195193
self.options = options # type: Dict[str, Any]
196194
self._worker = BackgroundWorker(queue_size=options["transport_queue_size"])
197195
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
198-
self._disabled_until = {} # type: Dict[DataCategory, datetime]
196+
self._disabled_until = {} # type: Dict[Optional[EventDataCategory], datetime]
199197
self._retry = urllib3.util.Retry()
200198
self._discarded_events = defaultdict(
201199
int
202-
) # type: DefaultDict[Tuple[str, str], int]
200+
) # type: DefaultDict[Tuple[EventDataCategory, str], int]
203201
self._last_client_report_sent = time.time()
204202

205203
compresslevel = options.get("_experiments", {}).get(
@@ -224,7 +222,7 @@ def __init__(
224222
def record_lost_event(
225223
self,
226224
reason, # type: str
227-
data_category=None, # type: Optional[str]
225+
data_category=None, # type: Optional[EventDataCategory]
228226
item=None, # type: Optional[Item]
229227
):
230228
# type: (...) -> None

sentry_sdk/types.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from typing import TYPE_CHECKING
1212

1313
if TYPE_CHECKING:
14-
from sentry_sdk._types import Event, Hint
14+
from sentry_sdk._types import Event, EventDataCategory, Hint
1515
else:
1616
from typing import Any
1717

1818
# The lines below allow the types to be imported from outside `if TYPE_CHECKING`
1919
# guards. The types in this module are only intended to be used for type hints.
2020
Event = Any
21+
EventDataCategory = Any
2122
Hint = Any
2223

23-
__all__ = ("Event", "Hint")
24+
__all__ = ("Event", "EventDataCategory", "Hint")

0 commit comments

Comments
 (0)