Skip to content

Commit 403dd9e

Browse files
BabyChrist666claude
andcommitted
fix: correct pyright type and coverage in handler registration tests
Use Server[Any] instead of Server[None] to match the default lifespan return type, and add pragma: no cover to dummy handler bodies that are only used for registration verification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1a65641 commit 403dd9e

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

tests/server/lowlevel/test_handler_registration.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99

1010

1111
@pytest.fixture
12-
def server() -> Server[None]:
12+
def server() -> Server[Any]:
1313
return Server(name="test-server")
1414

1515

16-
async def _dummy_request_handler(ctx: ServerRequestContext[None], params: Any) -> dict[str, str]:
16+
async def _dummy_request_handler(ctx: ServerRequestContext[Any], params: Any) -> dict[str, str]: # pragma: no cover
1717
return {"result": "ok"}
1818

1919

20-
async def _dummy_notification_handler(ctx: ServerRequestContext[None], params: Any) -> None:
20+
async def _dummy_notification_handler(ctx: ServerRequestContext[Any], params: Any) -> None: # pragma: no cover
2121
pass
2222

2323

2424
class TestAddRequestHandler:
25-
def test_add_request_handler(self, server: Server[None]) -> None:
25+
def test_add_request_handler(self, server: Server[Any]) -> None:
2626
server.add_request_handler("custom/method", _dummy_request_handler)
2727
assert server.has_handler("custom/method")
2828

29-
def test_add_request_handler_replaces_existing(self, server: Server[None]) -> None:
30-
async def handler_a(ctx: ServerRequestContext[None], params: Any) -> str:
29+
def test_add_request_handler_replaces_existing(self, server: Server[Any]) -> None:
30+
async def handler_a(ctx: ServerRequestContext[Any], params: Any) -> str: # pragma: no cover
3131
return "a"
3232

33-
async def handler_b(ctx: ServerRequestContext[None], params: Any) -> str:
33+
async def handler_b(ctx: ServerRequestContext[Any], params: Any) -> str: # pragma: no cover
3434
return "b"
3535

3636
server.add_request_handler("custom/method", handler_a)
@@ -40,27 +40,27 @@ async def handler_b(ctx: ServerRequestContext[None], params: Any) -> str:
4040

4141

4242
class TestRemoveRequestHandler:
43-
def test_remove_request_handler(self, server: Server[None]) -> None:
43+
def test_remove_request_handler(self, server: Server[Any]) -> None:
4444
server.add_request_handler("custom/method", _dummy_request_handler)
4545
assert server.has_handler("custom/method")
4646
server.remove_request_handler("custom/method")
4747
assert not server.has_handler("custom/method")
4848

49-
def test_remove_request_handler_not_found(self, server: Server[None]) -> None:
49+
def test_remove_request_handler_not_found(self, server: Server[Any]) -> None:
5050
with pytest.raises(KeyError):
5151
server.remove_request_handler("nonexistent/method")
5252

5353

5454
class TestAddNotificationHandler:
55-
def test_add_notification_handler(self, server: Server[None]) -> None:
55+
def test_add_notification_handler(self, server: Server[Any]) -> None:
5656
server.add_notification_handler("custom/notify", _dummy_notification_handler)
5757
assert server.has_handler("custom/notify")
5858

59-
def test_add_notification_handler_replaces_existing(self, server: Server[None]) -> None:
60-
async def handler_a(ctx: ServerRequestContext[None], params: Any) -> None:
59+
def test_add_notification_handler_replaces_existing(self, server: Server[Any]) -> None:
60+
async def handler_a(ctx: ServerRequestContext[Any], params: Any) -> None: # pragma: no cover
6161
pass
6262

63-
async def handler_b(ctx: ServerRequestContext[None], params: Any) -> None:
63+
async def handler_b(ctx: ServerRequestContext[Any], params: Any) -> None: # pragma: no cover
6464
pass
6565

6666
server.add_notification_handler("custom/notify", handler_a)
@@ -69,29 +69,29 @@ async def handler_b(ctx: ServerRequestContext[None], params: Any) -> None:
6969

7070

7171
class TestRemoveNotificationHandler:
72-
def test_remove_notification_handler(self, server: Server[None]) -> None:
72+
def test_remove_notification_handler(self, server: Server[Any]) -> None:
7373
server.add_notification_handler("custom/notify", _dummy_notification_handler)
7474
assert server.has_handler("custom/notify")
7575
server.remove_notification_handler("custom/notify")
7676
assert not server.has_handler("custom/notify")
7777

78-
def test_remove_notification_handler_not_found(self, server: Server[None]) -> None:
78+
def test_remove_notification_handler_not_found(self, server: Server[Any]) -> None:
7979
with pytest.raises(KeyError):
8080
server.remove_notification_handler("nonexistent/notify")
8181

8282

8383
class TestHasHandler:
84-
def test_has_handler_request(self, server: Server[None]) -> None:
84+
def test_has_handler_request(self, server: Server[Any]) -> None:
8585
server.add_request_handler("custom/method", _dummy_request_handler)
8686
assert server.has_handler("custom/method")
8787

88-
def test_has_handler_notification(self, server: Server[None]) -> None:
88+
def test_has_handler_notification(self, server: Server[Any]) -> None:
8989
server.add_notification_handler("custom/notify", _dummy_notification_handler)
9090
assert server.has_handler("custom/notify")
9191

92-
def test_has_handler_unregistered(self, server: Server[None]) -> None:
92+
def test_has_handler_unregistered(self, server: Server[Any]) -> None:
9393
assert not server.has_handler("nonexistent/method")
9494

95-
def test_has_handler_default_ping(self, server: Server[None]) -> None:
95+
def test_has_handler_default_ping(self, server: Server[Any]) -> None:
9696
"""The ping handler is registered by default."""
9797
assert server.has_handler("ping")

0 commit comments

Comments
 (0)