Skip to content

Commit ec21faa

Browse files
use contextlib for nullcontext in mcp
1 parent 8cfedab commit ec21faa

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

sentry_sdk/integrations/_wsgi_common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import contextmanager
12
import json
23
from copy import deepcopy
34

@@ -51,6 +52,12 @@
5152
)
5253

5354

55+
# This noop context manager can be replaced with "from contextlib import nullcontext" when we drop Python 3.6 support
56+
@contextmanager
57+
def nullcontext() -> "Iterator[None]":
58+
yield
59+
60+
5461
def request_body_within_bounds(
5562
client: "Optional[sentry_sdk.client.BaseClient]", content_length: int
5663
) -> bool:

sentry_sdk/integrations/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from sentry_sdk.integrations._wsgi_common import (
2121
DEFAULT_HTTP_METHODS_TO_CAPTURE,
22+
nullcontext,
2223
)
2324
from sentry_sdk.sessions import track_session
2425
from sentry_sdk.tracing import (
@@ -33,7 +34,6 @@
3334
logger,
3435
transaction_from_function,
3536
_get_installed_modules,
36-
nullcontext,
3737
)
3838
from sentry_sdk.tracing import Transaction
3939

sentry_sdk/integrations/mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import inspect
1111
from functools import wraps
1212
from typing import TYPE_CHECKING
13+
from contextlib import nullcontext
1314

1415
import sentry_sdk
1516
from sentry_sdk.ai.utils import get_start_span_function
1617
from sentry_sdk.consts import OP, SPANDATA
1718
from sentry_sdk.integrations import Integration, DidNotEnable
1819
from sentry_sdk.utils import safe_serialize
1920
from sentry_sdk.scope import should_send_default_pii
20-
from sentry_sdk.utils import nullcontext
2121

2222
try:
2323
from mcp.server.lowlevel import Server # type: ignore[import-not-found]

sentry_sdk/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,9 +2108,3 @@ def serialize_attribute(val: "AttributeValue") -> "SerializedAttributeValue":
21082108
# Coerce to string if we don't know what to do with the value. This should
21092109
# never happen as we pre-format early in format_attribute, but let's be safe.
21102110
return {"value": safe_repr(val), "type": "string"}
2111-
2112-
2113-
# This noop context manager can be replaced with "from contextlib import nullcontext" when we drop Python 3.6 support
2114-
@contextmanager
2115-
def nullcontext() -> "Iterator[None]":
2116-
yield

0 commit comments

Comments
 (0)