Skip to content

Commit f5b7ac3

Browse files
fix: add type annotations and coverage pragma to tests
Github-Issue: #1283
1 parent cb38422 commit f5b7ac3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/issues/test_1283_idle_session_cleanup.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
"""
1717

1818
import time
19+
from collections.abc import Callable, Coroutine
20+
from typing import Any
1921

2022
import anyio
2123
import pytest
22-
from starlette.types import Message
24+
from starlette.types import Message, Scope
2325

2426
from mcp.server.lowlevel import Server
2527
from mcp.server.streamable_http import MCP_SESSION_ID_HEADER, StreamableHTTPServerTransport
2628
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
2729

2830

29-
def _make_scope() -> dict:
31+
def _make_scope() -> Scope:
3032
return {
3133
"type": "http",
3234
"method": "POST",
@@ -39,7 +41,7 @@ async def _mock_receive() -> Message: # pragma: no cover
3941
return {"type": "http.request", "body": b"", "more_body": False}
4042

4143

42-
def _make_send(sent: list[Message]):
44+
def _make_send(sent: list[Message]) -> Callable[[Message], Coroutine[Any, Any, None]]:
4345
async def mock_send(message: Message) -> None:
4446
sent.append(message)
4547

@@ -52,13 +54,15 @@ def _extract_session_id(sent_messages: list[Message]) -> str:
5254
for name, value in msg.get("headers", []):
5355
if name.decode().lower() == MCP_SESSION_ID_HEADER.lower():
5456
return value.decode()
55-
raise AssertionError("Session ID not found in response headers")
57+
raise AssertionError("Session ID not found in response headers") # pragma: no cover
5658

5759

58-
def _make_blocking_run(stop_event: anyio.Event):
60+
def _make_blocking_run(
61+
stop_event: anyio.Event,
62+
) -> Callable[..., Coroutine[Any, Any, None]]:
5963
"""Create a mock app.run that blocks until stop_event is set."""
6064

61-
async def blocking_run(*args, **kwargs): # type: ignore[no-untyped-def]
65+
async def blocking_run(*args: Any, **kwargs: Any) -> None:
6266
await stop_event.wait()
6367

6468
return blocking_run
@@ -277,7 +281,7 @@ async def test_run_server_exits_promptly_after_terminate():
277281

278282
original_run = app.run
279283

280-
async def instrumented_run(*args, **kwargs): # type: ignore[no-untyped-def]
284+
async def instrumented_run(*args: Any, **kwargs: Any) -> None:
281285
try:
282286
await original_run(*args, **kwargs)
283287
finally:
@@ -360,7 +364,7 @@ async def test_run_server_finally_block_runs_after_terminate():
360364
lifecycle_events: list[str] = []
361365
original_run = app.run
362366

363-
async def instrumented_run(*args, **kwargs): # type: ignore[no-untyped-def]
367+
async def instrumented_run(*args: Any, **kwargs: Any) -> None:
364368
lifecycle_events.append("run_entered")
365369
try:
366370
await original_run(*args, **kwargs)

0 commit comments

Comments
 (0)