@@ -147,7 +147,7 @@ def __init__(
147
147
}
148
148
self .notification_handlers : dict [type , Callable [..., Awaitable [None ]]] = {}
149
149
self .notification_options = NotificationOptions ()
150
- logger .debug (f "Initializing server ' { name } '" )
150
+ logger .debug ("Initializing server %r" , name )
151
151
152
152
def create_initialization_options (
153
153
self ,
@@ -510,7 +510,7 @@ async def run(
510
510
511
511
async with anyio .create_task_group () as tg :
512
512
async for message in session .incoming_messages :
513
- logger .debug (f "Received message: { message } " )
513
+ logger .debug ("Received message: %s" , message )
514
514
515
515
tg .start_soon (
516
516
self ._handle_message ,
@@ -543,7 +543,9 @@ async def _handle_message(
543
543
await self ._handle_notification (notify )
544
544
545
545
for warning in w :
546
- logger .info (f"Warning: { warning .category .__name__ } : { warning .message } " )
546
+ logger .info (
547
+ "Warning: %s: %s" , warning .category .__name__ , warning .message
548
+ )
547
549
548
550
async def _handle_request (
549
551
self ,
@@ -553,10 +555,9 @@ async def _handle_request(
553
555
lifespan_context : LifespanResultT ,
554
556
raise_exceptions : bool ,
555
557
):
556
- logger .info (f"Processing request of type { type (req ).__name__ } " )
557
- if type (req ) in self .request_handlers :
558
- handler = self .request_handlers [type (req )]
559
- logger .debug (f"Dispatching request of type { type (req ).__name__ } " )
558
+ logger .info ("Processing request of type %s" , type (req ).__name__ )
559
+ if handler := self .request_handlers .get (type (req )): # type: ignore
560
+ logger .debug ("Dispatching request of type %s" , type (req ).__name__ )
560
561
561
562
token = None
562
563
try :
@@ -602,16 +603,13 @@ async def _handle_request(
602
603
logger .debug ("Response sent" )
603
604
604
605
async def _handle_notification (self , notify : Any ):
605
- if type (notify ) in self .notification_handlers :
606
- assert type (notify ) in self .notification_handlers
607
-
608
- handler = self .notification_handlers [type (notify )]
609
- logger .debug (f"Dispatching notification of type { type (notify ).__name__ } " )
606
+ if handler := self .notification_handlers .get (type (notify )): # type: ignore
607
+ logger .debug ("Dispatching notification of type %s" , type (notify ).__name__ )
610
608
611
609
try :
612
610
await handler (notify )
613
- except Exception as err :
614
- logger .error ( f "Uncaught exception in notification handler: { err } " )
611
+ except Exception :
612
+ logger .exception ( "Uncaught exception in notification handler" )
615
613
616
614
617
615
async def _ping_handler (request : types .PingRequest ) -> types .ServerResult :
0 commit comments