Skip to content

Commit c4c5c1d

Browse files
committed
add fix for TRY301 lint error
1 parent 2db7f81 commit c4c5c1d

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ async def on_message_send(
283283
blocking = True # Default to blocking behavior
284284
if params.configuration and params.configuration.blocking is False:
285285
blocking = False
286-
287286
interrupted_or_non_blocking = False
288287
try:
289288
(
@@ -292,15 +291,6 @@ async def on_message_send(
292291
) = await result_aggregator.consume_and_break_on_interrupt(
293292
consumer, blocking=blocking
294293
)
295-
if not result:
296-
raise ServerError(error=InternalError()) # noqa: TRY301
297-
298-
if isinstance(result, Task):
299-
self._validate_task_id_match(task_id, result.id)
300-
301-
await self._send_push_notification_if_needed(
302-
task_id, result_aggregator
303-
)
304294

305295
except Exception:
306296
logger.exception('Agent execution failed')
@@ -314,6 +304,14 @@ async def on_message_send(
314304
else:
315305
await self._cleanup_producer(producer_task, task_id)
316306

307+
if not result:
308+
raise ServerError(error=InternalError())
309+
310+
if isinstance(result, Task):
311+
self._validate_task_id_match(task_id, result.id)
312+
313+
await self._send_push_notification_if_needed(task_id, result_aggregator)
314+
317315
return result
318316

319317
async def on_message_send_stream(

src/a2a/server/request_handlers/jsonrpc_handler.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,26 @@ async def on_cancel_task(
179179
task = await self.request_handler.on_cancel_task(
180180
request.params, context
181181
)
182-
if task:
183-
return prepare_response_object(
184-
request.id,
185-
task,
186-
(Task,),
187-
CancelTaskSuccessResponse,
188-
CancelTaskResponse,
189-
)
190-
raise ServerError(error=TaskNotFoundError()) # noqa: TRY301
191182
except ServerError as e:
192183
return CancelTaskResponse(
193184
root=JSONRPCErrorResponse(
194185
id=request.id, error=e.error if e.error else InternalError()
195186
)
196187
)
197188

189+
if task:
190+
return prepare_response_object(
191+
request.id,
192+
task,
193+
(Task,),
194+
CancelTaskSuccessResponse,
195+
CancelTaskResponse,
196+
)
197+
198+
return CancelTaskResponse(
199+
root=JSONRPCErrorResponse(id=request.id, error=TaskNotFoundError())
200+
)
201+
198202
async def on_resubscribe_to_task(
199203
self,
200204
request: TaskResubscriptionRequest,
@@ -331,22 +335,26 @@ async def on_get_task(
331335
task = await self.request_handler.on_get_task(
332336
request.params, context
333337
)
334-
if task:
335-
return prepare_response_object(
336-
request.id,
337-
task,
338-
(Task,),
339-
GetTaskSuccessResponse,
340-
GetTaskResponse,
341-
)
342-
raise ServerError(error=TaskNotFoundError()) # noqa: TRY301
343338
except ServerError as e:
344339
return GetTaskResponse(
345340
root=JSONRPCErrorResponse(
346341
id=request.id, error=e.error if e.error else InternalError()
347342
)
348343
)
349344

345+
if task:
346+
return prepare_response_object(
347+
request.id,
348+
task,
349+
(Task,),
350+
GetTaskSuccessResponse,
351+
GetTaskResponse,
352+
)
353+
354+
return GetTaskResponse(
355+
root=JSONRPCErrorResponse(id=request.id, error=TaskNotFoundError())
356+
)
357+
350358
async def list_push_notification_config(
351359
self,
352360
request: ListTaskPushNotificationConfigRequest,

0 commit comments

Comments
 (0)