@@ -143,7 +143,7 @@ def __init__(
143
143
}
144
144
self .notification_handlers : dict [type , Callable [..., Awaitable [None ]]] = {}
145
145
self .notification_options = NotificationOptions ()
146
- logger .debug (f "Initializing server ' { name } '" )
146
+ logger .debug ("Initializing server %r" , name )
147
147
148
148
def create_initialization_options (
149
149
self ,
@@ -483,7 +483,7 @@ async def run(
483
483
484
484
async with anyio .create_task_group () as tg :
485
485
async for message in session .incoming_messages :
486
- logger .debug (f "Received message: { message } " )
486
+ logger .debug ("Received message: %s" , message )
487
487
488
488
tg .start_soon (
489
489
self ._handle_message ,
@@ -510,7 +510,9 @@ async def _handle_message(
510
510
await self ._handle_notification (notify )
511
511
512
512
for warning in w :
513
- logger .info (f"Warning: { warning .category .__name__ } : { warning .message } " )
513
+ logger .info (
514
+ "Warning: %s: %s" , warning .category .__name__ , warning .message
515
+ )
514
516
515
517
async def _handle_request (
516
518
self ,
@@ -520,10 +522,9 @@ async def _handle_request(
520
522
lifespan_context : LifespanResultT ,
521
523
raise_exceptions : bool ,
522
524
):
523
- logger .info (f"Processing request of type { type (req ).__name__ } " )
524
- if type (req ) in self .request_handlers :
525
- handler = self .request_handlers [type (req )]
526
- logger .debug (f"Dispatching request of type { type (req ).__name__ } " )
525
+ logger .info ("Processing request of type %s" , type (req ).__name__ )
526
+ if handler := self .request_handlers .get (type (req )): # type: ignore
527
+ logger .debug ("Dispatching request of type %s" , type (req ).__name__ )
527
528
528
529
token = None
529
530
try :
@@ -567,16 +568,13 @@ async def _handle_request(
567
568
logger .debug ("Response sent" )
568
569
569
570
async def _handle_notification (self , notify : Any ):
570
- if type (notify ) in self .notification_handlers :
571
- assert type (notify ) in self .notification_handlers
572
-
573
- handler = self .notification_handlers [type (notify )]
574
- logger .debug (f"Dispatching notification of type { type (notify ).__name__ } " )
571
+ if handler := self .notification_handlers .get (type (notify )): # type: ignore
572
+ logger .debug ("Dispatching notification of type %s" , type (notify ).__name__ )
575
573
576
574
try :
577
575
await handler (notify )
578
- except Exception as err :
579
- logger .error ( f "Uncaught exception in notification handler: { err } " )
576
+ except Exception :
577
+ logger .exception ( "Uncaught exception in notification handler" )
580
578
581
579
582
580
async def _ping_handler (request : types .PingRequest ) -> types .ServerResult :
0 commit comments