diff --git a/aiojobs/_scheduler.py b/aiojobs/_scheduler.py index 9a483c5..bdcd7f9 100644 --- a/aiojobs/_scheduler.py +++ b/aiojobs/_scheduler.py @@ -10,6 +10,7 @@ Optional, Set, Type, + TypedDict, TypeVar, Union, ) @@ -24,9 +25,17 @@ Self = TypeVar("Self", bound="Scheduler") + +class ExceptionHandlerDict(TypedDict, total=False): + message: str + job: Job + exception: Exception + source_traceback: TracebackType + + _T = TypeVar("_T") _FutureLike = Union["asyncio.Future[_T]", Awaitable[_T]] -ExceptionHandler = Callable[["Scheduler", Dict[str, Any]], None] +ExceptionHandler = Callable[["Scheduler", ExceptionHandlerDict], None] class Scheduler(Collection[Job[object]]): @@ -225,7 +234,7 @@ async def close(self) -> None: self._failed_tasks.put_nowait(None) await self._failed_task - def call_exception_handler(self, context: Dict[str, Any]) -> None: + def call_exception_handler(self, context: ExceptionHandlerDict) -> None: if self._exception_handler is None: asyncio.get_running_loop().call_exception_handler(context) else: