Skip to content

Commit 97161dc

Browse files
committed
fix(spans): fixing mypy issues
1 parent 30a4b1f commit 97161dc

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

sentry_sdk/client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Mapping
66
from datetime import datetime, timezone
77
from importlib import import_module
8-
from typing import cast, overload
8+
from typing import TYPE_CHECKING, List, Dict, cast, overload
99
import warnings
1010

1111
from sentry_sdk._compat import PY37, check_uwsgi_thread_support
@@ -46,8 +46,6 @@
4646
from sentry_sdk.monitor import Monitor
4747
from sentry_sdk.spotlight import setup_spotlight
4848

49-
from typing import TYPE_CHECKING
50-
5149
if TYPE_CHECKING:
5250
from typing import Any
5351
from typing import Callable
@@ -491,7 +489,7 @@ def _prepare_event(
491489

492490
if scope is not None:
493491
is_transaction = event.get("type") == "transaction"
494-
spans_before = len(cast(list[dict[str, object]], event.get("spans", [])))
492+
spans_before = len(cast(List[Dict[str, object]], event.get("spans", [])))
495493
event_ = scope.apply_to_event(event, hint, self.options)
496494

497495
# one of the event/error processors returned None
@@ -511,7 +509,7 @@ def _prepare_event(
511509

512510
event = event_
513511
spans_delta = spans_before - len(
514-
cast(list[dict[str, object]], event.get("spans", []))
512+
cast(List[Dict[str, object]], event.get("spans", []))
515513
)
516514
if is_transaction and spans_delta > 0 and self.transport is not None:
517515
self.transport.record_lost_event(
@@ -611,7 +609,7 @@ def _prepare_event(
611609
and event.get("type") == "transaction"
612610
):
613611
new_event = None
614-
spans_before = len(cast(list[dict[str, object]], event.get("spans", [])))
612+
spans_before = len(cast(List[Dict[str, object]], event.get("spans", [])))
615613
with capture_internal_exceptions():
616614
new_event = before_send_transaction(event, hint or {})
617615
if new_event is None:

sentry_sdk/scrubber.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
iter_event_frames,
55
)
66

7-
from typing import TYPE_CHECKING, cast
7+
from typing import TYPE_CHECKING, cast, List, Dict
88

99
if TYPE_CHECKING:
1010
from sentry_sdk._types import Event
11-
from typing import List
1211
from typing import Optional
1312

1413

@@ -161,7 +160,7 @@ def scrub_spans(self, event):
161160
# type: (Event) -> None
162161
with capture_internal_exceptions():
163162
if "spans" in event:
164-
for span in cast(list[dict[str, object]], event["spans"]):
163+
for span in cast(List[Dict[str, object]], event["spans"]):
165164
if "data" in span:
166165
self.scrub_dict(span["data"])
167166

sentry_sdk/transport.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
from sentry_sdk.worker import BackgroundWorker
2525
from sentry_sdk.envelope import Envelope, Item, PayloadRef
2626

27-
from typing import TYPE_CHECKING, cast
27+
from typing import TYPE_CHECKING, cast, List, Dict
2828

2929
if TYPE_CHECKING:
3030
from typing import Any
3131
from typing import Callable
32-
from typing import Dict
3332
from typing import DefaultDict
3433
from typing import Iterable
35-
from typing import List
3634
from typing import Mapping
3735
from typing import Optional
3836
from typing import Self
@@ -281,7 +279,7 @@ def record_lost_event(
281279

282280
# +1 for the transaction itself
283281
span_count = (
284-
len(cast(list[dict[str, object]], event.get("spans") or [])) + 1
282+
len(cast(List[Dict[str, object]], event.get("spans") or [])) + 1
285283
)
286284
self.record_lost_event(reason, "span", quantity=span_count)
287285

@@ -722,7 +720,7 @@ def _request(
722720

723721
try:
724722
import httpcore
725-
import h2 # type: ignore # noqa: F401
723+
import h2 # noqa: F401
726724
except ImportError:
727725
# Sorry, no Http2Transport for you
728726
class Http2Transport(HttpTransport):

0 commit comments

Comments
 (0)