@@ -147,7 +147,7 @@ def __init__(
147147 }
148148 self .notification_handlers : dict [type , Callable [..., Awaitable [None ]]] = {}
149149 self .notification_options = NotificationOptions ()
150- logger .debug (f "Initializing server ' { name } '" )
150+ logger .debug ("Initializing server %r" , name )
151151
152152 def create_initialization_options (
153153 self ,
@@ -601,7 +601,7 @@ async def run(
601601
602602 async with anyio .create_task_group () as tg :
603603 async for message in session .incoming_messages :
604- logger .debug (f "Received message: { message } " )
604+ logger .debug ("Received message: %s" , message )
605605
606606 tg .start_soon (
607607 self ._handle_message ,
@@ -634,7 +634,9 @@ async def _handle_message(
634634 await self ._handle_notification (notify )
635635
636636 for warning in w :
637- logger .info (f"Warning: { warning .category .__name__ } : { warning .message } " )
637+ logger .info (
638+ "Warning: %s: %s" , warning .category .__name__ , warning .message
639+ )
638640
639641 async def _handle_request (
640642 self ,
@@ -644,10 +646,9 @@ async def _handle_request(
644646 lifespan_context : LifespanResultT ,
645647 raise_exceptions : bool ,
646648 ):
647- logger .info (f"Processing request of type { type (req ).__name__ } " )
648- if type (req ) in self .request_handlers :
649- handler = self .request_handlers [type (req )]
650- logger .debug (f"Dispatching request of type { type (req ).__name__ } " )
649+ logger .info ("Processing request of type %s" , type (req ).__name__ )
650+ if handler := self .request_handlers .get (type (req )): # type: ignore
651+ logger .debug ("Dispatching request of type %s" , type (req ).__name__ )
651652
652653 token = None
653654 try :
@@ -693,16 +694,13 @@ async def _handle_request(
693694 logger .debug ("Response sent" )
694695
695696 async def _handle_notification (self , notify : Any ):
696- if type (notify ) in self .notification_handlers :
697- assert type (notify ) in self .notification_handlers
698-
699- handler = self .notification_handlers [type (notify )]
700- logger .debug (f"Dispatching notification of type { type (notify ).__name__ } " )
697+ if handler := self .notification_handlers .get (type (notify )): # type: ignore
698+ logger .debug ("Dispatching notification of type %s" , type (notify ).__name__ )
701699
702700 try :
703701 await handler (notify )
704- except Exception as err :
705- logger .error ( f "Uncaught exception in notification handler: { err } " )
702+ except Exception :
703+ logger .exception ( "Uncaught exception in notification handler" )
706704
707705
708706async def _ping_handler (request : types .PingRequest ) -> types .ServerResult :
0 commit comments