From 02f5de3d8405d5d91c0f1cb6411459de422789c5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 2 Apr 2019 20:11:40 +0300 Subject: [PATCH 1/3] Copy type hints and signatures between hub.py and api.py --- sentry_sdk/api.py | 6 ++++-- sentry_sdk/hub.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index 227ac49685..dc6abfa17c 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -35,6 +35,7 @@ def hubmethod(f): @hubmethod def capture_event(event, hint=None): + # type: (Dict[str, Any], Dict[str, Any]) -> Optional[str] hub = Hub.current if hub is not None: return hub.capture_event(event, hint) @@ -59,10 +60,11 @@ def capture_exception(error=None): @hubmethod -def add_breadcrumb(*args, **kwargs): +def add_breadcrumb(crumb=None, hint=None, **kwargs): + # type: (Dict[str, Any], Dict[str, Any], **Any) -> None hub = Hub.current if hub is not None: - return hub.add_breadcrumb(*args, **kwargs) + return hub.add_breadcrumb(crumb, hint, **kwargs) @overload # noqa diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 0cbb6b025f..5517d759ea 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -241,6 +241,7 @@ def client(self): return self._stack[-1][0] def last_event_id(self): + # type: () -> Optional[str] """Returns the last event ID.""" return self._last_event_id From cf630eedb2aa2f1f15f29a38a486d039f52073d0 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 2 Apr 2019 20:12:22 +0300 Subject: [PATCH 2/3] Fix the type hint for capture_exception() Fixes #313 --- sentry_sdk/api.py | 2 +- sentry_sdk/hub.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index dc6abfa17c..778ad29c91 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -52,7 +52,7 @@ def capture_message(message, level=None): @hubmethod def capture_exception(error=None): - # type: (ValueError) -> Optional[str] + # type: (Optional[BaseException]) -> Optional[str] hub = Hub.current if hub is not None: return hub.capture_exception(error) diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 5517d759ea..03d5a469df 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -279,6 +279,7 @@ def capture_message(self, message, level=None): return self.capture_event({"message": message, "level": level}) def capture_exception(self, error=None): + # type: (Optional[BaseException]) -> Optional[str] """Captures an exception. The argument passed can be `None` in which case the last exception From 3edd7a5c2f95959f7c7a2f56ca3a5ced220d8835 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 3 Apr 2019 22:15:29 +0200 Subject: [PATCH 3/3] fix: mypy --- sentry_sdk/api.py | 2 ++ sentry_sdk/hub.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index 778ad29c91..cc6ea14d6a 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -10,6 +10,7 @@ from typing import Optional from typing import overload from typing import Callable + from typing import Dict from contextlib import ContextManager else: @@ -39,6 +40,7 @@ def capture_event(event, hint=None): hub = Hub.current if hub is not None: return hub.capture_event(event, hint) + return None @hubmethod diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 03d5a469df..d81bf0171b 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -288,7 +288,7 @@ def capture_exception(self, error=None): """ client = self.client if client is None: - return + return None if error is None: exc_info = sys.exc_info() else: @@ -300,6 +300,8 @@ def capture_exception(self, error=None): except Exception: self._capture_internal_exception(sys.exc_info()) + return None + def _capture_internal_exception(self, exc_info): """Capture an exception that is likely caused by a bug in the SDK itself."""