Skip to content

Commit

Permalink
ref(transport): Improve event data category typing
Browse files Browse the repository at this point in the history
Done to more clearly define event data categories, in preparation for #3229.
  • Loading branch information
szokeasaurusrex committed Jul 8, 2024
1 parent 70b12c3 commit 9b6a718
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 6 additions & 8 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
from urllib3.poolmanager import PoolManager
from urllib3.poolmanager import ProxyManager

from sentry_sdk._types import Event

DataCategory = Optional[str]
from sentry_sdk._types import Event, EventDataCategory

KEEP_ALIVE_SOCKET_OPTIONS = []
for option in [
Expand Down Expand Up @@ -133,7 +131,7 @@ def kill(self):
def record_lost_event(
self,
reason, # type: str
data_category=None, # type: Optional[str]
data_category=None, # type: Optional[EventDataCategory]
item=None, # type: Optional[Item]
):
# type: (...) -> None
Expand All @@ -155,7 +153,7 @@ def __del__(self):


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

Expand Down Expand Up @@ -195,11 +193,11 @@ def __init__(
self.options = options # type: Dict[str, Any]
self._worker = BackgroundWorker(queue_size=options["transport_queue_size"])
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
self._disabled_until = {} # type: Dict[DataCategory, datetime]
self._disabled_until = {} # type: Dict[Optional[EventDataCategory], datetime]
self._retry = urllib3.util.Retry()
self._discarded_events = defaultdict(
int
) # type: DefaultDict[Tuple[str, str], int]
) # type: DefaultDict[Tuple[EventDataCategory, str], int]
self._last_client_report_sent = time.time()

compresslevel = options.get("_experiments", {}).get(
Expand All @@ -224,7 +222,7 @@ def __init__(
def record_lost_event(
self,
reason, # type: str
data_category=None, # type: Optional[str]
data_category=None, # type: Optional[EventDataCategory]
item=None, # type: Optional[Item]
):
# type: (...) -> None
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from sentry_sdk._types import Event, Hint
from sentry_sdk._types import Event, EventDataCategory, Hint
else:
from typing import Any

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

__all__ = ("Event", "Hint")
__all__ = ("Event", "EventDataCategory", "Hint")

0 comments on commit 9b6a718

Please sign in to comment.