1818
1919if False :
2020 from contextlib import ContextManager
21+ from sys import _OptExcInfo
2122
2223 from typing import Union
2324 from typing import Any
2627 from typing import List
2728 from typing import Callable
2829 from typing import Generator
30+ from typing import Type
2931 from typing import overload
3032
3133 from sentry_sdk .integrations import Integration
@@ -36,8 +38,8 @@ def overload(x):
3638 return x
3739
3840
39- _local = ContextVar ("sentry_current_hub" )
40- _initial_client = None
41+ _local = ContextVar ("sentry_current_hub" ) # type: ignore
42+ _initial_client = None # type: Optional[weakref.ReferenceType[Client]]
4143
4244
4345def _should_send_default_pii ():
@@ -50,9 +52,11 @@ def _should_send_default_pii():
5052
5153class _InitGuard (object ):
5254 def __init__ (self , client ):
55+ # type: (Client) -> None
5356 self ._client = client
5457
5558 def __enter__ (self ):
59+ # type: () -> _InitGuard
5660 return self
5761
5862 def __exit__ (self , exc_type , exc_value , tb ):
@@ -103,6 +107,7 @@ def __exit__(self, exc_type, exc_value, tb):
103107
104108class _ScopeManager (object ):
105109 def __init__ (self , hub ):
110+ # type: (Hub) -> None
106111 self ._hub = hub
107112 self ._original_len = len (hub ._stack )
108113 self ._layer = hub ._stack [- 1 ]
@@ -157,8 +162,13 @@ class Hub(with_metaclass(HubMeta)): # type: ignore
157162
158163 _stack = None # type: List[Tuple[Optional[Client], Scope]]
159164
165+ # Mypy doesn't pick up on the metaclass.
166+ if False :
167+ current = ... # type: Hub
168+ main = ... # type: Hub
169+
160170 def __init__ (self , client_or_hub = None , scope = None ):
161- # type: (Union[Hub, Client], Optional[Any]) -> None
171+ # type: (Optional[ Union[Hub, Client] ], Optional[Any]) -> None
162172 if isinstance (client_or_hub , Hub ):
163173 hub = client_or_hub
164174 client , other_scope = hub ._stack [- 1 ]
@@ -197,7 +207,7 @@ def run(self, callback):
197207 return callback ()
198208
199209 def get_integration (self , name_or_class ):
200- # type: (Union[str, Integration]) -> Any
210+ # type: (Union[str, Type[ Integration] ]) -> Any
201211 """Returns the integration for this hub by name or class. If there
202212 is no client bound or the client does not have that integration
203213 then `None` is returned.
@@ -218,9 +228,10 @@ def get_integration(self, name_or_class):
218228 if rv is not None :
219229 return rv
220230
221- initial_client = _initial_client
222- if initial_client is not None :
223- initial_client = initial_client ()
231+ if _initial_client is not None :
232+ initial_client = _initial_client ()
233+ else :
234+ initial_client = None
224235
225236 if (
226237 initial_client is not None
@@ -254,7 +265,7 @@ def bind_client(self, new):
254265 self ._stack [- 1 ] = (new , top [1 ])
255266
256267 def capture_event (self , event , hint = None ):
257- # type: (Event, Hint) -> Optional[str]
268+ # type: (Event, Optional[ Hint] ) -> Optional[str]
258269 """Captures an event. The return value is the ID of the event.
259270
260271 The event is a dictionary following the Sentry v7/v8 protocol
@@ -306,9 +317,10 @@ def capture_exception(self, error=None):
306317 return None
307318
308319 def _capture_internal_exception (self , exc_info ):
320+ # type: (_OptExcInfo) -> Any
309321 """Capture an exception that is likely caused by a bug in the SDK
310322 itself."""
311- logger .error ("Internal error in sentry_sdk" , exc_info = exc_info )
323+ logger .error ("Internal error in sentry_sdk" , exc_info = exc_info ) # type: ignore
312324
313325 def add_breadcrumb (self , crumb = None , hint = None , ** kwargs ):
314326 # type: (Optional[Breadcrumb], Optional[BreadcrumbHint], **Any) -> None
0 commit comments