Skip to content

ref(transport): Improve event data category typing #3243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading