Skip to content

Consider using TypedDict for 2nd ExceptionHandler parameter #565

@sh-at-cs

Description

@sh-at-cs

The ExceptionHandler type is currently defined as taking a dict[str, Any] as its 2nd parameter:

ExceptionHandler = Callable[["Scheduler", Dict[str, Any]], None]

But the docs explain that the set of keys of this dictionary is actually static:

aiojobs/docs/api.rst

Lines 161 to 168 in 70fe9e5

*context* is a :class:`dict` with the following keys:
* *message*: error message, :class:`str`
* *job*: failed job, :class:`Job` instance
* *exception*: caught exception, :exc:`Exception` instance
* *source_traceback*: a traceback at the moment of job creation
(present only for debug event loops, see also
:envvar:`PYTHONASYNCIODEBUG`).

So it would be better for type-safety (and things that come with it like IDE completion) if this used a TypedDict instead of a generic dict[str, Any].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions