Skip to content

Commit bfe7a59

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

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎sentry_sdk/transport.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
from urllib3.poolmanager import PoolManager
3434
from urllib3.poolmanager import ProxyManager
3535

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

4038

4139
KEEP_ALIVE_SOCKET_OPTIONS = []
@@ -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,7 +193,7 @@ 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

‎sentry_sdk/types.py‎

Lines changed: 3 additions & 2 deletions
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)