Add pyright strict mode on the whole project (#1254)

This commit is contained in:
Marcelo Trylesinski 2025-08-11 19:56:37 +02:00 • committed by GitHub
commit c7671e470c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
from collections.abc import AsyncGenerator
from typing import Any
import anyio
import pytest
@ -7,16 +8,14 @@ import mcp.types as types
from mcp.client.session import ClientSession
from mcp.server.lowlevel.server import Server
from mcp.shared.exceptions import McpError
from mcp.shared.memory import (
create_client_server_memory_streams,
create_connected_server_and_client_session,
)
from mcp.shared.memory import create_client_server_memory_streams, create_connected_server_and_client_session
from mcp.types import (
CancelledNotification,
CancelledNotificationParams,
ClientNotification,
ClientRequest,
EmptyResult,
TextContent,
)
@ -61,7 +60,7 @@ async def test_request_cancellation():
# Register the tool handler
@server.call_tool()
async def handle_call_tool(name: str, arguments: dict | None) -> list:
async def handle_call_tool(name: str, arguments: dict[str, Any] | None) -> list[TextContent]:
nonlocal request_id, ev_tool_called
if name == "slow_tool":
request_id = server.request_context.request_id
@ -83,7 +82,7 @@ async def test_request_cancellation():
return server
async def make_request(client_session):
async def make_request(client_session: ClientSession):
nonlocal ev_cancelled
try:
await client_session.send_request(
@ -134,14 +133,11 @@ async def test_connection_closed():
ev_closed = anyio.Event()
ev_response = anyio.Event()
async with create_client_server_memory_streams() as (
client_streams,
server_streams,
):
async with create_client_server_memory_streams() as (client_streams, server_streams):
client_read, client_write = client_streams
server_read, server_write = server_streams
async def make_request(client_session):
async def make_request(client_session: ClientSession):
"""Send a request in a separate task"""
nonlocal ev_response
try:
@ -165,10 +161,7 @@ async def test_connection_closed():
async with (
anyio.create_task_group() as tg,
ClientSession(
read_stream=client_read,
write_stream=client_write,
) as client_session,
ClientSession(read_stream=client_read, write_stream=client_write) as client_session,
):
tg.start_soon(make_request, client_session)
tg.start_soon(mock_server)