Skip to content

Commit 4b199bc

Browse files
BabyChrist666claude
andcommitted
Fix pyright type errors and branch coverage in tests
- Add type: ignore comments for IPython imports (reportMissingImports, etc.) - Add pragma: no branch for async context manager branches in Jupyter tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bad0a6e commit 4b199bc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/mcp/client/stdio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def _is_jupyter_environment() -> bool:
3737
"""
3838
try:
3939
# Check for IPython kernel
40-
from IPython import get_ipython
40+
from IPython import get_ipython # type: ignore[reportMissingImports]
4141

42-
ipython = get_ipython()
42+
ipython = get_ipython() # type: ignore[reportUnknownVariableType]
4343
if ipython is not None:
4444
# Check if it's a notebook kernel (not just IPython terminal)
45-
if "IPKernelApp" in ipython.config:
45+
if "IPKernelApp" in ipython.config: # type: ignore[reportUnknownMemberType]
4646
return True
4747
# Also check for ZMQInteractiveShell which indicates notebook
48-
if ipython.__class__.__name__ == "ZMQInteractiveShell":
48+
if ipython.__class__.__name__ == "ZMQInteractiveShell": # type: ignore[reportUnknownMemberType]
4949
return True
5050
except (ImportError, AttributeError):
5151
pass

tests/client/test_stdio.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,10 @@ async def test_stderr_reader_jupyter_mode(self):
769769
# Mock _is_jupyter_environment to return True to exercise stderr_reader
770770
with patch("mcp.client.stdio._is_jupyter_environment", return_value=True):
771771
with anyio.move_on_after(5.0) as cancel_scope:
772-
async with stdio_client(server_params) as (read_stream, write_stream):
772+
async with stdio_client(server_params) as ( # pragma: no branch
773+
read_stream,
774+
write_stream,
775+
):
773776
await anyio.sleep(1.0)
774777

775778
assert not cancel_scope.cancelled_caught, "stdio_client should not hang in Jupyter mode"
@@ -798,7 +801,10 @@ async def test_stderr_reader_jupyter_mode_continuous(self):
798801

799802
with patch("mcp.client.stdio._is_jupyter_environment", return_value=True):
800803
with anyio.move_on_after(5.0) as cancel_scope:
801-
async with stdio_client(server_params) as (read_stream, write_stream):
804+
async with stdio_client(server_params) as ( # pragma: no branch
805+
read_stream,
806+
write_stream,
807+
):
802808
await anyio.sleep(1.0)
803809

804810
assert not cancel_scope.cancelled_caught, "stdio_client should handle continuous Jupyter stderr"

0 commit comments

Comments
 (0)