Skip to content

Commit 06a933d

Browse files
committed
Fix weird util function
1 parent ba00e86 commit 06a933d

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

sentry_sdk/utils.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
from sentry_sdk._types import Annotated, AnnotatedValue, SENSITIVE_DATA_SUBSTITUTE
3737

38-
from typing import TYPE_CHECKING, cast, overload
38+
from typing import TYPE_CHECKING, overload
3939

4040
if TYPE_CHECKING:
4141
from types import FrameType, TracebackType
@@ -1679,11 +1679,6 @@ def reraise(
16791679
raise value
16801680

16811681

1682-
def _no_op(*_a: Any, **_k: Any) -> None:
1683-
"""No-op function for ensure_integration_enabled."""
1684-
pass
1685-
1686-
16871682
if TYPE_CHECKING:
16881683

16891684
@overload
@@ -1700,8 +1695,8 @@ def ensure_integration_enabled(
17001695

17011696
def ensure_integration_enabled(
17021697
integration: type[sentry_sdk.integrations.Integration],
1703-
original_function: Union[Callable[P, R], Callable[P, None]] = _no_op,
1704-
) -> Callable[[Callable[P, R]], Callable[P, R]]:
1698+
original_function: Optional[Callable[P, R]] = None,
1699+
) -> Callable[[Callable[P, R]], Callable[P, Optional[R]]]:
17051700
"""
17061701
Ensures a given integration is enabled prior to calling a Sentry-patched function.
17071702
@@ -1723,23 +1718,21 @@ def patch_my_function():
17231718
return my_function()
17241719
```
17251720
"""
1726-
if TYPE_CHECKING:
1727-
# Type hint to ensure the default function has the right typing. The overloads
1728-
# ensure the default _no_op function is only used when R is None.
1729-
original_function = cast("Callable[P, R]", original_function)
1730-
1731-
def patcher(sentry_patched_function: Callable[P, R]) -> Callable[P, R]:
1732-
def runner(*args: "P.args", **kwargs: "P.kwargs") -> R:
1733-
if sentry_sdk.get_client().get_integration(integration) is None:
1734-
return original_function(*args, **kwargs)
17351721

1736-
return sentry_patched_function(*args, **kwargs)
1722+
def patcher(sentry_patched_function: Callable[P, R]) -> Callable[P, Optional[R]]:
1723+
def runner(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
1724+
if sentry_sdk.get_client().get_integration(integration) is not None:
1725+
return sentry_patched_function(*args, **kwargs)
1726+
elif original_function is not None:
1727+
return original_function(*args, **kwargs)
1728+
else:
1729+
return None
17371730

1738-
if original_function is _no_op:
1731+
if original_function:
1732+
return wraps(original_function)(runner)
1733+
else:
17391734
return wraps(sentry_patched_function)(runner)
17401735

1741-
return wraps(original_function)(runner)
1742-
17431736
return patcher
17441737

17451738

0 commit comments

Comments
 (0)