Skip to content

Commit 8bc17a0

Browse files
author
RJ Lopez
committed
fix: cleanup wrongly marked coverage pragmas exercised by regression test
1 parent 6f262a5 commit 8bc17a0

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/mcp/client/session_group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(
146146
self._session_exit_stacks = {}
147147
self._component_name_hook = component_name_hook
148148

149-
async def __aenter__(self) -> Self: # pragma: no cover
149+
async def __aenter__(self) -> Self:
150150
# Enter the exit stack only if we created it ourselves
151151
if self._owns_exit_stack:
152152
await self._exit_stack.__aenter__()
@@ -157,7 +157,7 @@ async def __aexit__(
157157
_exc_type: type[BaseException] | None,
158158
_exc_val: BaseException | None,
159159
_exc_tb: TracebackType | None,
160-
) -> bool | None: # pragma: no cover
160+
) -> bool | None:
161161
"""Closes session exit stacks and main exit stack upon completion."""
162162

163163
# Only close the main exit stack if we created it
@@ -323,7 +323,7 @@ async def _establish_session(
323323
await self._exit_stack.enter_async_context(session_stack)
324324

325325
return result.server_info, session
326-
except Exception: # pragma: no cover
326+
except Exception:
327327
# If anything during this setup fails, ensure the session-specific
328328
# stack is closed.
329329
await session_stack.aclose()

src/mcp/shared/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ async def _handle_session_message(message: SessionMessage) -> None:
451451
try:
452452
await stream.send(JSONRPCError(jsonrpc="2.0", id=id, error=error))
453453
await stream.aclose()
454-
except Exception: # pragma: no cover
454+
except Exception:
455455
# Stream might already be closed
456456
pass
457457
self._response_streams.clear()

tests/client/test_session_group.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import sys
66
from unittest import mock
77

8-
if sys.version_info < (3, 11):
9-
from exceptiongroup import BaseExceptionGroup # pragma: no cover # noqa: A004
8+
if sys.version_info < (3, 11): # pragma: lax no cover
9+
from exceptiongroup import BaseExceptionGroup
10+
else: # pragma: lax no cover
11+
BaseExceptionGroup = ExceptionGroup
1012

1113
import httpx
1214
import pytest
@@ -418,10 +420,10 @@ def _walk(e: BaseException | None) -> bool:
418420
return False
419421
seen.add(id(e))
420422
if isinstance(e, RuntimeError) and "cancel scope" in str(e).lower():
421-
return True # pragma: no cover
423+
return True
422424
if isinstance(e, BaseExceptionGroup):
423-
if any(_walk(child) for child in e.exceptions): # type: ignore # pragma: no cover
424-
return True # pragma: no cover
425+
if any(_walk(child) for child in e.exceptions): # type: ignore
426+
return True
425427
return _walk(e.__cause__) or _walk(e.__context__)
426428

427429
return _walk(exc)
@@ -447,7 +449,7 @@ async def test_unreachable_streamable_http_error_is_catchable() -> None:
447449
except BaseException as inner:
448450
# Expected post-fix: real ConnectError lands here.
449451
caught = inner
450-
except BaseException as outer: # pragma: no cover
452+
except BaseException as outer: # pragma: lax no cover
451453
# If we land here, the error escaped past the inner handler --
452454
# that is the regression case (masking RuntimeError surfacing
453455
# from __aexit__ instead of the real ConnectError propagating).

0 commit comments

Comments
 (0)