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
7 changed files with 452 additions and 925 deletions

View file

@ -1,6 +1,4 @@
"""
Tests for refactored OAuth client authentication implementation.
"""
"""Tests for refactored OAuth client authentication implementation."""
import base64
import time

View file

@ -1,5 +1,4 @@
"""
Tests for Unicode handling in streamable HTTP transport.
"""Tests for Unicode handling in streamable HTTP transport.
Verifies that Unicode text is correctly transmitted and received in both directions
(server→client and client→server) using the streamable HTTP transport.

View file

@ -1,5 +1,4 @@
"""
Tests for StreamableHTTP client transport with non-SDK servers.
"""Tests for StreamableHTTP client transport with non-SDK servers.
These tests verify client behavior when interacting with servers
that don't follow SDK conventions.
@ -110,8 +109,7 @@ def non_sdk_server(non_sdk_server_port: int) -> Generator[None, None, None]:
@pytest.mark.anyio
async def test_non_compliant_notification_response(non_sdk_server: None, non_sdk_server_port: int) -> None:
"""
This test verifies that the client ignores unexpected responses to notifications: the spec states they should
"""This test verifies that the client ignores unexpected responses to notifications: the spec states they should
either be 202 + no response body, or 4xx + optional error body
(https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#sending-messages-to-the-server),
but some servers wrongly return other 2xx codes (e.g. 204). For now we simply ignore unexpected responses

View file

@ -14,8 +14,7 @@ from mcp.types import Tool
@contextmanager
def bypass_server_output_validation():
"""
Context manager that bypasses server-side output validation.
"""Context manager that bypasses server-side output validation.
This simulates a malicious or non-compliant server that doesn't validate
its outputs, allowing us to test client-side validation.
"""

View file

@ -11,8 +11,7 @@ from mcp.types import ClientNotification, ClientRequest, ClientResult, EmptyResu
@pytest.mark.anyio
async def test_send_request_stream_cleanup():
"""
Test that send_request properly cleans up streams when an exception occurs.
"""Test that send_request properly cleans up streams when an exception occurs.
This test mocks out most of the session functionality to focus on stream cleanup.
"""

View file

@ -1,5 +1,4 @@
"""
Regression test for issue #1630: OAuth2 scope incorrectly set to resource_metadata URL.
"""Regression test for issue #1630: OAuth2 scope incorrectly set to resource_metadata URL.
This test verifies that when a 401 response contains both resource_metadata and scope
in the WWW-Authenticate header, the actual scope is used (not the resource_metadata URL).
@ -37,8 +36,7 @@ class MockTokenStorage:
@pytest.mark.anyio
async def test_401_uses_www_auth_scope_not_resource_metadata_url():
"""
Regression test for #1630: Ensure scope is extracted from WWW-Authenticate header,
"""Regression test for #1630: Ensure scope is extracted from WWW-Authenticate header,
not the resource_metadata URL.
When a 401 response contains:

View file

@ -106,8 +106,7 @@ async def test_stdio_client_nonexistent_command():
@pytest.mark.anyio
async def test_stdio_client_universal_cleanup():
"""
Test that stdio_client completes cleanup within reasonable time
"""Test that stdio_client completes cleanup within reasonable time
even when connected to processes that exit slowly.
"""
@ -159,9 +158,7 @@ async def test_stdio_client_universal_cleanup():
@pytest.mark.anyio
@pytest.mark.skipif(sys.platform == "win32", reason="Windows signal handling is different")
async def test_stdio_client_sigint_only_process(): # pragma: no cover
"""
Test cleanup with a process that ignores SIGTERM but responds to SIGINT.
"""
"""Test cleanup with a process that ignores SIGTERM but responds to SIGINT."""
# Create a Python script that ignores SIGTERM but handles SIGINT
script_content = textwrap.dedent(
"""
@ -225,8 +222,7 @@ async def test_stdio_client_sigint_only_process(): # pragma: no cover
class TestChildProcessCleanup:
"""
Tests for child process cleanup functionality using _terminate_process_tree.
"""Tests for child process cleanup functionality using _terminate_process_tree.
These tests verify that child processes are properly terminated when the parent
is killed, addressing the issue where processes like npx spawn child processes
@ -252,8 +248,7 @@ class TestChildProcessCleanup:
@pytest.mark.anyio
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
async def test_basic_child_process_cleanup(self):
"""
Test basic parent-child process cleanup.
"""Test basic parent-child process cleanup.
Parent spawns a single child process that writes continuously to a file.
"""
# Create a marker file for the child process to write to
@ -344,8 +339,7 @@ class TestChildProcessCleanup:
@pytest.mark.anyio
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
async def test_nested_process_tree(self):
"""
Test nested process tree cleanup (parent → child → grandchild).
"""Test nested process tree cleanup (parent → child → grandchild).
Each level writes to a different file to verify all processes are terminated.
"""
# Create temporary files for each process level
@ -440,8 +434,7 @@ class TestChildProcessCleanup:
@pytest.mark.anyio
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
async def test_early_parent_exit(self):
"""
Test cleanup when parent exits during termination sequence.
"""Test cleanup when parent exits during termination sequence.
Tests the race condition where parent might die during our termination
sequence but we can still clean up the children via the process group.
"""
@ -517,8 +510,7 @@ class TestChildProcessCleanup:
@pytest.mark.anyio
async def test_stdio_client_graceful_stdin_exit():
"""
Test that a process exits gracefully when stdin is closed,
"""Test that a process exits gracefully when stdin is closed,
without needing SIGTERM or SIGKILL.
"""
# Create a Python script that exits when stdin is closed
@ -573,8 +565,7 @@ async def test_stdio_client_graceful_stdin_exit():
@pytest.mark.anyio
async def test_stdio_client_stdin_close_ignored():
"""
Test that when a process ignores stdin closure, the shutdown sequence
"""Test that when a process ignores stdin closure, the shutdown sequence
properly escalates to SIGTERM.
"""
# Create a Python script that ignores stdin closure but responds to SIGTERM