Repository: getsentry/sentry-python

Issue:
Incorrect signature for capture_exception
The type hint for `capture_exception()` implies only `ValueError`s can be passed in, which causes a type check warning in IDEs such as PyCharm when you pass in a non-ValueError exception.

https://github.com/getsentry/sentry-python/blob/62e3a647e5787957dcabc889bce5d53538dc423e/sentry_sdk/api.py#L53-L54

I suppose the hint should be more like

```python
# type: (BaseException) -> Optional[str] 
```


Discussion:
You're completely right. The type hints were partially generated using [pyannotate](https://github.com/dropbox/pyannotate) and are therefore still quite a bit too restrictive. Do you want to make a PR? Otherwise I will fix it soon (tm).

Resolving patch:
diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py
--- 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:
 
@@ -35,9 +36,11 @@ 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)
+    return None
 
 
 @hubmethod
@@ -51,7 +54,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)
@@ -59,10 +62,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
--- 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
 
@@ -278,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
@@ -286,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:
@@ -298,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."""


Test patch: