chore: add D212 lint rule to enforce Google-style docstrings (#1892)

This commit is contained in:
Felix Weinberger 2026-01-16 16:10:52 +00:00 • committed by GitHub
commit d41d0c0128
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 452 additions and 925 deletions

View file

@ -1,5 +1,4 @@
"""
Regression test for issue #1027: Ensure cleanup procedures run properly during shutdown
"""Regression test for issue #1027: Ensure cleanup procedures run properly during shutdown
Issue #1027 reported that cleanup code after "yield" in lifespan was unreachable when
processes were terminated. This has been fixed by implementing the MCP spec-compliant
@ -23,8 +22,7 @@ from tests.shared.test_win32_utils import escape_path_for_python
@pytest.mark.anyio
async def test_lifespan_cleanup_executed():
"""
Regression test ensuring MCP server cleanup code runs during shutdown.
"""Regression test ensuring MCP server cleanup code runs during shutdown.
This test verifies that the fix for issue #1027 works correctly by:
1. Starting an MCP server that writes a marker file on startup
@ -124,8 +122,7 @@ async def test_lifespan_cleanup_executed():
@pytest.mark.anyio
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
async def test_stdin_close_triggers_cleanup():
"""
Regression test verifying the stdin-based graceful shutdown mechanism.
"""Regression test verifying the stdin-based graceful shutdown mechanism.
This test ensures the core fix for issue #1027 continues to work by:
1. Manually managing a server process

View file

@ -90,8 +90,7 @@ class ServerThread(threading.Thread):
def check_logs_for_race_condition_errors(caplog: pytest.LogCaptureFixture, test_name: str) -> None:
"""
Check logs for ClosedResourceError and other race condition errors.
"""Check logs for ClosedResourceError and other race condition errors.
Args:
caplog: pytest log capture fixture
@ -121,8 +120,7 @@ def check_logs_for_race_condition_errors(caplog: pytest.LogCaptureFixture, test_
@pytest.mark.anyio
async def test_race_condition_invalid_accept_headers(caplog: pytest.LogCaptureFixture):
"""
Test the race condition with invalid Accept headers.
"""Test the race condition with invalid Accept headers.
This test reproduces the exact scenario described in issue #1363:
- Send POST request with incorrect Accept headers (missing either application/json or text/event-stream)
@ -196,8 +194,7 @@ async def test_race_condition_invalid_accept_headers(caplog: pytest.LogCaptureFi
@pytest.mark.anyio
async def test_race_condition_invalid_content_type(caplog: pytest.LogCaptureFixture):
"""
Test the race condition with invalid Content-Type headers.
"""Test the race condition with invalid Content-Type headers.
This test reproduces the race condition scenario with Content-Type validation failure.
"""
@ -237,8 +234,7 @@ async def test_race_condition_invalid_content_type(caplog: pytest.LogCaptureFixt
@pytest.mark.anyio
async def test_race_condition_message_router_async_for(caplog: pytest.LogCaptureFixture):
"""
Uses json_response=True to trigger the `if self.is_json_response_enabled` branch,
"""Uses json_response=True to trigger the `if self.is_json_response_enabled` branch,
which reproduces the ClosedResourceError when message_router is suspended
in async for loop while transport cleanup closes streams concurrently.
"""

View file

@ -13,8 +13,7 @@ from mcp.client.stdio import stdio_client
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test") # pragma: no cover
@pytest.mark.anyio
async def test_windows_stdio_client_with_session():
"""
Test the exact scenario from issue #552: Using ClientSession with stdio_client.
"""Test the exact scenario from issue #552: Using ClientSession with stdio_client.
This reproduces the original bug report where stdio_client hangs on Windows 11
when used with ClientSession.

View file

@ -20,8 +20,7 @@ from mcp.types import (
@pytest.mark.anyio
async def test_malformed_initialize_request_does_not_crash_server():
"""
Test that malformed initialize requests return proper error responses
"""Test that malformed initialize requests return proper error responses
instead of crashing the server (HackerOne #3156202).
"""
# Create in-memory streams for testing
@ -101,9 +100,7 @@ async def test_malformed_initialize_request_does_not_crash_server():
@pytest.mark.anyio
async def test_multiple_concurrent_malformed_requests():
"""
Test that multiple concurrent malformed requests don't crash the server.
"""
"""Test that multiple concurrent malformed requests don't crash the server."""
# Create in-memory streams for testing
read_send_stream, read_receive_stream = anyio.create_memory_object_stream[SessionMessage | Exception](100)
write_send_stream, write_receive_stream = anyio.create_memory_object_stream[SessionMessage](100)