Skip to content

feat(typing): annotate Event more uniformly #2431

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion sentry_sdk/crons/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
if TYPE_CHECKING:
from typing import Any, Dict, Optional

from sentry_sdk._types import Event


def _create_check_in_event(
monitor_slug=None,
Expand All @@ -15,7 +17,7 @@ def _create_check_in_event(
duration_s=None,
monitor_config=None,
):
# type: (Optional[str], Optional[str], Optional[str], Optional[float], Optional[Dict[str, Any]]) -> Dict[str, Any]
# type: (Optional[str], Optional[str], Optional[str], Optional[float], Optional[Dict[str, Any]]) -> Event
options = Hub.current.client.options if Hub.current.client else {}
check_in_id = check_in_id or uuid.uuid4().hex # type: str

Expand Down
10 changes: 6 additions & 4 deletions sentry_sdk/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ def add_session(
):
# type: (...) -> None
if isinstance(session, Session):
session = session.to_json()
self.add_item(Item(payload=PayloadRef(json=session), type="session"))
json = session.to_json()
else:
json = session
self.add_item(Item(payload=PayloadRef(json=json), type="session"))

def add_sessions(
self, sessions # type: Any
self, sessions # type: Event
):
# type: (...) -> None
self.add_item(Item(payload=PayloadRef(json=sessions), type="sessions"))
Expand Down Expand Up @@ -160,7 +162,7 @@ def __init__(
self,
bytes=None, # type: Optional[bytes]
path=None, # type: Optional[Union[bytes, text_type]]
json=None, # type: Optional[Any]
json=None, # type: Optional[Event]
):
# type: (...) -> None
self.json = json
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def __call__(self, event, context):
return ChaliceEventSourceHandler.__call__(self, event, context)
except Exception:
exc_info = sys.exc_info()
event, hint = event_from_exception(
sentry_event, hint = event_from_exception(
exc_info,
client_options=client.options,
mechanism={"type": "chalice", "handled": False},
)
hub.capture_event(event, hint=hint)
hub.capture_event(sentry_event, hint=hint)
hub.flush()
reraise(*exc_info)

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/spark/spark_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _capture_exception(exc_info, hub):
if rv:
rv.reverse()
hint = event_hint_with_exc_info(exc_info)
event = {"level": "error", "exception": {"values": rv}}
event = {"level": "error", "exception": {"values": rv}} # type: Event

_tag_task_context()

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Any
from typing import Dict

from sentry_sdk._types import SessionStatus
from sentry_sdk._types import Event, SessionStatus


def _minute_trunc(ts):
Expand Down Expand Up @@ -155,7 +155,7 @@ def get_json_attrs(
return attrs

def to_json(self):
# type: (...) -> Any
# type: (...) -> Event
rv = {
"sid": str(self.sid),
"init": True,
Expand Down
4 changes: 3 additions & 1 deletion sentry_sdk/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from typing import Optional
from typing import Union

from sentry_sdk._types import Event


def is_auto_session_tracking_enabled(hub=None):
# type: (Optional[sentry_sdk.Hub]) -> Union[Any, bool, None]
Expand Down Expand Up @@ -55,7 +57,7 @@ def auto_session_tracking(hub=None, session_mode="application"):


def make_aggregate_envelope(aggregate_states, attrs):
# type: (Any, Any) -> Any
# type: (Any, Any) -> Event
return {"attrs": dict(attrs), "aggregates": list(aggregate_states.values())}


Expand Down
9 changes: 7 additions & 2 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@
Union,
)

from sentry_sdk._types import EndpointType, ExcInfo
from sentry_sdk._types import (
EndpointType,
Event,
ExcInfo,
Hint,
)


epoch = datetime(1970, 1, 1)
Expand Down Expand Up @@ -1053,7 +1058,7 @@ def event_from_exception(
client_options=None, # type: Optional[Dict[str, Any]]
mechanism=None, # type: Optional[Dict[str, Any]]
):
# type: (...) -> Tuple[Dict[str, Any], Dict[str, Any]]
# type: (...) -> Tuple[Event, Hint]
exc_info = exc_info_from_error(exc_info)
hint = event_hint_with_exc_info(exc_info)
return (
Expand Down