@@ -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 ,
@@ -601,7 +601,7 @@ async def run(
601
601
602
602
async with anyio .create_task_group () as tg :
603
603
async for message in session .incoming_messages :
604
- logger .debug (f "Received message: { message } " )
604
+ logger .debug ("Received message: %s" , message )
605
605
606
606
tg .start_soon (
607
607
self ._handle_message ,
@@ -634,7 +634,9 @@ async def _handle_message(
634
634
await self ._handle_notification (notify )
635
635
636
636
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
+ )
638
640
639
641
async def _handle_request (
640
642
self ,
@@ -644,10 +646,9 @@ async def _handle_request(
644
646
lifespan_context : LifespanResultT ,
645
647
raise_exceptions : bool ,
646
648
):
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__ )
651
652
652
653
token = None
653
654
try :
@@ -693,16 +694,13 @@ async def _handle_request(
693
694
logger .debug ("Response sent" )
694
695
695
696
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__ )
701
699
702
700
try :
703
701
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" )
706
704
707
705
708
706
async def _ping_handler (request : types .PingRequest ) -> types .ServerResult :
0 commit comments