Skip to content

Commit 9305fad

Browse files
akxuntitaker
authored andcommitted
Type hint fixes (getsentry#315)
* Copy type hints and signatures between hub.py and api.py * Fix the type hint for capture_exception() Fixes getsentry#313 * fix: mypy
1 parent d36a591 commit 9305fad

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

sentry_sdk/api.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Optional
1111
from typing import overload
1212
from typing import Callable
13+
from typing import Dict
1314
from contextlib import ContextManager
1415
else:
1516

@@ -35,9 +36,11 @@ def hubmethod(f):
3536

3637
@hubmethod
3738
def capture_event(event, hint=None):
39+
# type: (Dict[str, Any], Dict[str, Any]) -> Optional[str]
3840
hub = Hub.current
3941
if hub is not None:
4042
return hub.capture_event(event, hint)
43+
return None
4144

4245

4346
@hubmethod
@@ -51,18 +54,19 @@ def capture_message(message, level=None):
5154

5255
@hubmethod
5356
def capture_exception(error=None):
54-
# type: (ValueError) -> Optional[str]
57+
# type: (Optional[BaseException]) -> Optional[str]
5558
hub = Hub.current
5659
if hub is not None:
5760
return hub.capture_exception(error)
5861
return None
5962

6063

6164
@hubmethod
62-
def add_breadcrumb(*args, **kwargs):
65+
def add_breadcrumb(crumb=None, hint=None, **kwargs):
66+
# type: (Dict[str, Any], Dict[str, Any], **Any) -> None
6367
hub = Hub.current
6468
if hub is not None:
65-
return hub.add_breadcrumb(*args, **kwargs)
69+
return hub.add_breadcrumb(crumb, hint, **kwargs)
6670

6771

6872
@overload # noqa

sentry_sdk/hub.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def client(self):
241241
return self._stack[-1][0]
242242

243243
def last_event_id(self):
244+
# type: () -> Optional[str]
244245
"""Returns the last event ID."""
245246
return self._last_event_id
246247

@@ -278,6 +279,7 @@ def capture_message(self, message, level=None):
278279
return self.capture_event({"message": message, "level": level})
279280

280281
def capture_exception(self, error=None):
282+
# type: (Optional[BaseException]) -> Optional[str]
281283
"""Captures an exception.
282284
283285
The argument passed can be `None` in which case the last exception
@@ -286,7 +288,7 @@ def capture_exception(self, error=None):
286288
"""
287289
client = self.client
288290
if client is None:
289-
return
291+
return None
290292
if error is None:
291293
exc_info = sys.exc_info()
292294
else:
@@ -298,6 +300,8 @@ def capture_exception(self, error=None):
298300
except Exception:
299301
self._capture_internal_exception(sys.exc_info())
300302

303+
return None
304+
301305
def _capture_internal_exception(self, exc_info):
302306
"""Capture an exception that is likely caused by a bug in the SDK
303307
itself."""

0 commit comments

Comments
 (0)