Skip to content

Commit 8d691f9

Browse files
ref(types): Correct ExcInfo type
Previously, we defined `ExcInfo` as `tuple[Type[BaseException] | None, BaseException | None, TracebackType | None]`, when in fact, the correct type is the narrower `tuple[Type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]`.
1 parent 2cb2dca commit 8d691f9

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

sentry_sdk/_types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@
121121
total=False,
122122
)
123123

124-
ExcInfo = Tuple[
125-
Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]
124+
ExcInfo = Union[
125+
tuple[Type[BaseException], BaseException, Optional[TracebackType]],
126+
tuple[None, None, None],
126127
]
127128

128129
Hint = Dict[str, Any]

sentry_sdk/integrations/sanic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@
2828
from typing import Callable
2929
from typing import Optional
3030
from typing import Union
31-
from typing import Tuple
3231
from typing import Dict
3332

3433
from sanic.request import Request, RequestParameters
3534
from sanic.response import BaseHTTPResponse
3635

37-
from sentry_sdk._types import Event, EventProcessor, Hint
36+
from sentry_sdk._types import Event, EventProcessor, ExcInfo, Hint
3837
from sanic.router import Route
3938

4039
try:
@@ -325,7 +324,7 @@ def _legacy_router_get(self, *args):
325324

326325
@ensure_integration_enabled(SanicIntegration)
327326
def _capture_exception(exception):
328-
# type: (Union[Tuple[Optional[type], Optional[BaseException], Any], BaseException]) -> None
327+
# type: (Union[ExcInfo, BaseException]) -> None
329328
with capture_internal_exceptions():
330329
event, hint = event_from_exception(
331330
exception,

sentry_sdk/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,14 @@ def exc_info_from_error(error):
10191019
else:
10201020
raise ValueError("Expected Exception object to report, got %s!" % type(error))
10211021

1022-
return exc_type, exc_value, tb
1022+
exc_info = (exc_type, exc_value, tb)
1023+
1024+
if TYPE_CHECKING:
1025+
# This cast is safe because exc_type and exc_value are either both
1026+
# None or both not None.
1027+
exc_info = cast(ExcInfo, exc_info)
1028+
1029+
return exc_info
10231030

10241031

10251032
def event_from_exception(

0 commit comments

Comments
 (0)