1919from sentry_sdk .integrations import setup_integrations
2020from sentry_sdk .utils import ContextVar
2121
22+ if False :
23+ from sentry_sdk .consts import ClientOptions
24+ from sentry_sdk .scope import Scope
25+ from typing import Any
26+ from typing import Dict
27+ from typing import Optional
28+
2229
2330_client_init_debug = ContextVar ("client_init_debug" )
2431
2532
2633def get_options (* args , ** kwargs ):
34+ # type: (*str, **ClientOptions) -> ClientOptions
2735 if args and (isinstance (args [0 ], string_types ) or args [0 ] is None ):
28- dsn = args [0 ]
36+ dsn = args [0 ] # type: Optional[str]
2937 args = args [1 :]
3038 else :
3139 dsn = None
3240
3341 rv = dict (DEFAULT_OPTIONS )
34- options = dict (* args , ** kwargs )
42+ options = dict (* args , ** kwargs ) # type: ignore
3543 if dsn is not None and options .get ("dsn" ) is None :
36- options ["dsn" ] = dsn
44+ options ["dsn" ] = dsn # type: ignore
3745
3846 for key , value in options .items ():
3947 if key not in rv :
4048 raise TypeError ("Unknown option %r" % (key ,))
41- rv [key ] = value
49+ rv [key ] = value # type: ignore
4250
4351 if rv ["dsn" ] is None :
4452 rv ["dsn" ] = os .environ .get ("SENTRY_DSN" )
4553
46- return rv
54+ return rv # type: ignore
4755
4856
4957class Client (object ):
@@ -54,6 +62,7 @@ class Client(object):
5462 """
5563
5664 def __init__ (self , * args , ** kwargs ):
65+ # type: (*str, **ClientOptions) -> None
5766 old_debug = _client_init_debug .get (False )
5867 try :
5968 self .options = options = get_options (* args , ** kwargs )
@@ -79,7 +88,13 @@ def dsn(self):
7988 """Returns the configured DSN as string."""
8089 return self .options ["dsn" ]
8190
82- def _prepare_event (self , event , hint , scope ):
91+ def _prepare_event (
92+ self ,
93+ event , # type: Dict[str, Any]
94+ hint , # type: Optional[Dict[str, Any]]
95+ scope , # type: Optional[Scope]
96+ ):
97+ # type: (...) -> Optional[Dict[str, Any]]
8398 if event .get ("timestamp" ) is None :
8499 event ["timestamp" ] = datetime .utcnow ()
85100
@@ -104,8 +119,8 @@ def _prepare_event(self, event, hint, scope):
104119 ]
105120
106121 for key in "release" , "environment" , "server_name" , "dist" :
107- if event .get (key ) is None and self .options [key ] is not None :
108- event [key ] = text_type (self .options [key ]).strip ()
122+ if event .get (key ) is None and self .options [key ] is not None : # type: ignore
123+ event [key ] = text_type (self .options [key ]).strip () # type: ignore
109124 if event .get ("sdk" ) is None :
110125 sdk_info = dict (SDK_INFO )
111126 sdk_info ["integrations" ] = sorted (self .integrations .keys ())
@@ -132,11 +147,12 @@ def _prepare_event(self, event, hint, scope):
132147 new_event = before_send (event , hint )
133148 if new_event is None :
134149 logger .info ("before send dropped event (%s)" , event )
135- event = new_event
150+ event = new_event # type: ignore
136151
137152 return event
138153
139- def _is_ignored_error (self , event , hint = None ):
154+ def _is_ignored_error (self , event , hint ):
155+ # type: (Dict[str, Any], Dict[str, Any]) -> bool
140156 exc_info = hint .get ("exc_info" )
141157 if exc_info is None :
142158 return False
@@ -156,7 +172,13 @@ def _is_ignored_error(self, event, hint=None):
156172
157173 return False
158174
159- def _should_capture (self , event , hint , scope = None ):
175+ def _should_capture (
176+ self ,
177+ event , # type: Dict[str, Any]
178+ hint , # type: Dict[str, Any]
179+ scope = None , # type: Scope
180+ ):
181+ # type: (...) -> bool
160182 if scope is not None and not scope ._should_capture :
161183 return False
162184
@@ -172,6 +194,7 @@ def _should_capture(self, event, hint, scope=None):
172194 return True
173195
174196 def capture_event (self , event , hint = None , scope = None ):
197+ # type: (Dict[str, Any], Any, Scope) -> Optional[str]
175198 """Captures an event.
176199
177200 This takes the ready made event and an optoinal hint and scope. The
@@ -183,17 +206,17 @@ def capture_event(self, event, hint=None, scope=None):
183206 value of this function will be the ID of the captured event.
184207 """
185208 if self .transport is None :
186- return
209+ return None
187210 if hint is None :
188211 hint = {}
189212 rv = event .get ("event_id" )
190213 if rv is None :
191214 event ["event_id" ] = rv = uuid .uuid4 ().hex
192215 if not self ._should_capture (event , hint , scope ):
193- return
194- event = self ._prepare_event (event , hint , scope )
216+ return None
217+ event = self ._prepare_event (event , hint , scope ) # type: ignore
195218 if event is None :
196- return
219+ return None
197220 self .transport .capture_event (event )
198221 return rv
199222
0 commit comments