@@ -385,27 +385,29 @@ async def _tasks_monitor(self) -> None:
385385 updates ["result_field" ] = result_field
386386 await self ._tasks_data .update_task_data (task_id , updates = updates )
387387
388- async def list_tasks (self , with_task_context : TaskContext | None ) -> list [TaskBase ]:
389- async def _ () -> list [TaskBase ]:
390- if not with_task_context :
391- return [
392- TaskBase (task_id = task .task_id )
393- for task in (await self ._tasks_data .list_tasks_data ())
394- ]
395-
388+ async def _list_tasks_unfiltered (
389+ self , with_task_context : TaskContext | None
390+ ) -> list [TaskBase ]:
391+ if not with_task_context :
396392 return [
397393 TaskBase (task_id = task .task_id )
398394 for task in (await self ._tasks_data .list_tasks_data ())
399- if task .task_context == with_task_context
400395 ]
401396
402- result = await _ ()
397+ return [
398+ TaskBase (task_id = task .task_id )
399+ for task in (await self ._tasks_data .list_tasks_data ())
400+ if task .task_context == with_task_context
401+ ]
403402
404- if len (result ) == 0 :
403+ async def list_tasks (self , with_task_context : TaskContext | None ) -> list [TaskBase ]:
404+ tasks_to_filter = await self ._list_tasks_unfiltered (with_task_context )
405+
406+ if len (tasks_to_filter ) == 0 :
405407 return []
406408
407- to_remove = await self ._tasks_data .list_tasks_to_remove ()
408- return [r for r in result if r .task_id not in to_remove ]
409+ to_exclude = await self ._tasks_data .list_tasks_to_remove ()
410+ return [r for r in tasks_to_filter if r .task_id not in to_exclude ]
409411
410412 async def _get_tracked_task (
411413 self , task_id : TaskId , with_task_context : TaskContext
0 commit comments