2020
2121
2222if False :
23+ from contextlib import ContextManager
24+
2325 from typing import Union
2426 from typing import Any
2527 from typing import Optional
26- from typing import Dict
2728 from typing import Tuple
2829 from typing import List
2930 from typing import Callable
31+ from typing import Generator
3032 from typing import overload
31- from contextlib import ContextManager
33+
3234 from sentry_sdk .integrations import Integration
35+ from sentry_sdk .utils import Event , Hint , Breadcrumb , BreadcrumbHint
3336else :
3437
3538 def overload (x ):
@@ -254,7 +257,7 @@ def bind_client(self, new):
254257 self ._stack [- 1 ] = (new , top [1 ])
255258
256259 def capture_event (self , event , hint = None ):
257- # type: (Dict[str, Any], Dict[str, Any] ) -> Optional[str]
260+ # type: (Event, Hint ) -> Optional[str]
258261 """Captures an event. The return value is the ID of the event.
259262
260263 The event is a dictionary following the Sentry v7/v8 protocol
@@ -271,7 +274,7 @@ def capture_event(self, event, hint=None):
271274 return None
272275
273276 def capture_message (self , message , level = None ):
274- # type: (str, Optional[Any ]) -> Optional[str]
277+ # type: (str, Optional[str ]) -> Optional[str]
275278 """Captures a message. The message is just a string. If no level
276279 is provided the default level is `info`.
277280 """
@@ -311,7 +314,7 @@ def _capture_internal_exception(self, exc_info):
311314 logger .error ("Internal error in sentry_sdk" , exc_info = exc_info )
312315
313316 def add_breadcrumb (self , crumb = None , hint = None , ** kwargs ):
314- # type: (Dict[str, Any ], Dict[str, Any ], **Any) -> None
317+ # type: (Optional[Breadcrumb ], Optional[BreadcrumbHint ], **Any) -> None
315318 """Adds a breadcrumb. The breadcrumbs are a dictionary with the
316319 data as the sentry v7/v8 protocol expects. `hint` is an optional
317320 value that can be used by `before_breadcrumb` to customize the
@@ -322,26 +325,27 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
322325 logger .info ("Dropped breadcrumb because no client bound" )
323326 return
324327
325- crumb = dict (crumb or ()) # type: Dict[str, Any]
328+ crumb = dict (crumb or ()) # type: Breadcrumb
326329 crumb .update (kwargs )
327330 if not crumb :
328331 return
329332
330- hint = dict (hint or ())
333+ hint = dict (hint or ()) # type: Hint
331334
332335 if crumb .get ("timestamp" ) is None :
333336 crumb ["timestamp" ] = datetime .utcnow ()
334337 if crumb .get ("type" ) is None :
335338 crumb ["type" ] = "default"
336339
337- original_crumb = crumb
338340 if client .options ["before_breadcrumb" ] is not None :
339- crumb = client .options ["before_breadcrumb" ](crumb , hint )
341+ new_crumb = client .options ["before_breadcrumb" ](crumb , hint )
342+ else :
343+ new_crumb = crumb
340344
341- if crumb is not None :
342- scope ._breadcrumbs .append (crumb )
345+ if new_crumb is not None :
346+ scope ._breadcrumbs .append (new_crumb )
343347 else :
344- logger .info ("before breadcrumb dropped breadcrumb (%s)" , original_crumb )
348+ logger .info ("before breadcrumb dropped breadcrumb (%s)" , crumb )
345349
346350 max_breadcrumbs = client .options ["max_breadcrumbs" ] # type: int
347351 while len (scope ._breadcrumbs ) > max_breadcrumbs :
@@ -472,12 +476,14 @@ def inner():
472476 return inner ()
473477
474478 def flush (self , timeout = None , callback = None ):
479+ # type: (Optional[float], Optional[Callable[[int, float], None]]) -> None
475480 """Alias for self.client.flush"""
476481 client , scope = self ._stack [- 1 ]
477482 if client is not None :
478483 return client .flush (timeout = timeout , callback = callback )
479484
480485 def iter_trace_propagation_headers (self ):
486+ # type: () -> Generator[Tuple[str, str], None, None]
481487 client , scope = self ._stack [- 1 ]
482488 if scope ._span is None :
483489 return
0 commit comments