Skip to content
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

feat(typing): annotate Event more uniformly #2431

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

Check warning on line 10 in sentry_sdk/crons/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/crons/api.py#L10

Added line #L10 was not covered by tests


def _create_check_in_event(
monitor_slug=None,
Expand All @@ -15,7 +17,7 @@
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 @@
):
# type: (...) -> None
if isinstance(session, Session):
session = session.to_json()
self.add_item(Item(payload=PayloadRef(json=session), type="session"))
json = session.to_json()

Check warning on line 82 in sentry_sdk/envelope.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/envelope.py#L82

Added line #L82 was not covered by tests
else:
json = session
self.add_item(Item(payload=PayloadRef(json=json), type="session"))

Check warning on line 85 in sentry_sdk/envelope.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/envelope.py#L84-L85

Added lines #L84 - L85 were not covered by tests

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 @@
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 @@
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

Check warning on line 61 in sentry_sdk/integrations/spark/spark_worker.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/spark/spark_worker.py#L61

Added line #L61 was not covered by tests

_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

Check warning on line 14 in sentry_sdk/session.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/session.py#L14

Added line #L14 was not covered by tests


def _minute_trunc(ts):
Expand Down Expand Up @@ -155,7 +155,7 @@
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

Check warning on line 21 in sentry_sdk/sessions.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/sessions.py#L21

Added line #L21 was not covered by tests


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 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 (

Check warning on line 71 in sentry_sdk/utils.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/utils.py#L71

Added line #L71 was not covered by tests
EndpointType,
Event,
ExcInfo,
Hint,
)


epoch = datetime(1970, 1, 1)
Expand Down Expand Up @@ -1053,7 +1058,7 @@
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
Loading