Skip to content

Commit 16bbe44

Browse files
committed
Fix types for serverless
1 parent 4c8b4e9 commit 16bbe44

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

sentry_sdk/integrations/serverless.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,36 @@
88
from typing import TYPE_CHECKING, overload
99

1010
if TYPE_CHECKING:
11-
from typing import Any
11+
from typing import NoReturn
1212
from typing import Callable
1313
from typing import TypeVar
14+
from typing import ParamSpec
1415
from typing import Union
1516
from typing import Optional
1617

17-
F = TypeVar("F", bound=Callable[..., Any])
18+
T = TypeVar("T")
19+
P = ParamSpec("P")
20+
21+
22+
if TYPE_CHECKING:
1823

1924
@overload
20-
def serverless_function(f: F, flush: bool = True) -> F:
25+
def serverless_function(f: Callable[P, T], flush: bool = True) -> Callable[P, T]:
2126
pass
2227

2328
@overload
24-
def serverless_function(f: None = None, flush: bool = True) -> Callable[[F], F]:
29+
def serverless_function(
30+
f: None = None, flush: bool = True
31+
) -> Callable[[Callable[P, T]], Callable[P, T]]:
2532
pass
2633

2734

2835
def serverless_function(
29-
f: Optional[F] = None, flush: bool = True
30-
) -> Union[F, Callable[[F], F]]:
31-
def wrapper(f: F) -> F:
36+
f: Optional[Callable[P, T]] = None, flush: bool = True
37+
) -> Union[Callable[P, T], Callable[[Callable[P, T]], Callable[P, T]]]:
38+
def wrapper(f: Callable[P, T]) -> Callable[P, T]:
3239
@wraps(f)
33-
def inner(*args: Any, **kwargs: Any) -> Any:
40+
def inner(*args: P.args, **kwargs: P.kwargs) -> T:
3441
with sentry_sdk.isolation_scope() as scope:
3542
scope.clear_breadcrumbs()
3643

@@ -42,15 +49,15 @@ def inner(*args: Any, **kwargs: Any) -> Any:
4249
if flush:
4350
sentry_sdk.flush()
4451

45-
return inner # type: ignore
52+
return inner
4653

4754
if f is None:
4855
return wrapper
4956
else:
5057
return wrapper(f)
5158

5259

53-
def _capture_and_reraise() -> None:
60+
def _capture_and_reraise() -> NoReturn:
5461
exc_info = sys.exc_info()
5562
client = sentry_sdk.get_client()
5663
if client.is_active():

0 commit comments

Comments
 (0)