Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(types): Correct ExcInfo type #3266

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@
total=False,
)

ExcInfo = Tuple[
Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]
ExcInfo = Union[
tuple[Type[BaseException], BaseException, Optional[TracebackType]],
tuple[None, None, None],
]

Hint = Dict[str, Any]
Expand Down
5 changes: 2 additions & 3 deletions sentry_sdk/integrations/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
from typing import Callable
from typing import Optional
from typing import Union
from typing import Tuple
from typing import Dict

from sanic.request import Request, RequestParameters
from sanic.response import BaseHTTPResponse

from sentry_sdk._types import Event, EventProcessor, Hint
from sentry_sdk._types import Event, EventProcessor, ExcInfo, Hint
from sanic.router import Route

try:
Expand Down Expand Up @@ -325,7 +324,7 @@ def _legacy_router_get(self, *args):

@ensure_integration_enabled(SanicIntegration)
def _capture_exception(exception):
# type: (Union[Tuple[Optional[type], Optional[BaseException], Any], BaseException]) -> None
# type: (Union[ExcInfo, BaseException]) -> None
with capture_internal_exceptions():
event, hint = event_from_exception(
exception,
Expand Down
9 changes: 8 additions & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,14 @@ def exc_info_from_error(error):
else:
raise ValueError("Expected Exception object to report, got %s!" % type(error))

return exc_type, exc_value, tb
exc_info = (exc_type, exc_value, tb)

if TYPE_CHECKING:
# This cast is safe because exc_type and exc_value are either both
# None or both not None.
exc_info = cast(ExcInfo, exc_info)

return exc_info


def event_from_exception(
Expand Down
Loading