@@ -151,7 +151,7 @@ def __init__(
151151 self .result_cache = ResultCache (max_cache_size , max_cache_ttl )
152152 self .notification_handlers : dict [type , Callable [..., Awaitable [None ]]] = {}
153153 self .notification_options = NotificationOptions ()
154- logger .debug (f "Initializing server ' { name } '" )
154+ logger .debug ("Initializing server %r" , name )
155155
156156 def create_initialization_options (
157157 self ,
@@ -542,7 +542,7 @@ async def run(
542542
543543 async with anyio .create_task_group () as tg :
544544 async for message in session .incoming_messages :
545- logger .debug (f "Received message: { message } " )
545+ logger .debug ("Received message: %s" , message )
546546
547547 tg .start_soon (
548548 self ._handle_message ,
@@ -575,7 +575,9 @@ async def _handle_message(
575575 await self ._handle_notification (notify )
576576
577577 for warning in w :
578- logger .info (f"Warning: { warning .category .__name__ } : { warning .message } " )
578+ logger .info (
579+ "Warning: %s: %s" , warning .category .__name__ , warning .message
580+ )
579581
580582 async def _handle_request (
581583 self ,
@@ -585,10 +587,9 @@ async def _handle_request(
585587 lifespan_context : LifespanResultT ,
586588 raise_exceptions : bool ,
587589 ):
588- logger .info (f"Processing request of type { type (req ).__name__ } " )
589- if type (req ) in self .request_handlers :
590- handler = self .request_handlers [type (req )]
591- logger .debug (f"Dispatching request of type { type (req ).__name__ } " )
590+ logger .info ("Processing request of type %s" , type (req ).__name__ )
591+ if handler := self .request_handlers .get (type (req )): # type: ignore
592+ logger .debug ("Dispatching request of type %s" , type (req ).__name__ )
592593
593594 token = None
594595 try :
@@ -634,16 +635,13 @@ async def _handle_request(
634635 logger .debug ("Response sent" )
635636
636637 async def _handle_notification (self , notify : Any ):
637- if type (notify ) in self .notification_handlers :
638- assert type (notify ) in self .notification_handlers
639-
640- handler = self .notification_handlers [type (notify )]
641- logger .debug (f"Dispatching notification of type { type (notify ).__name__ } " )
638+ if handler := self .notification_handlers .get (type (notify )): # type: ignore
639+ logger .debug ("Dispatching notification of type %s" , type (notify ).__name__ )
642640
643641 try :
644642 await handler (notify )
645- except Exception as err :
646- logger .error ( f "Uncaught exception in notification handler: { err } " )
643+ except Exception :
644+ logger .exception ( "Uncaught exception in notification handler" )
647645
648646
649647async def _ping_handler (request : types .PingRequest ) -> types .ServerResult :
0 commit comments