From ac827cb3c066ce3d0eabaccf3cc013e5a23c466a Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 17 Jun 2024 23:08:03 +0200 Subject: [PATCH] Add TypedDict for JobsSummary Fixes: ``` lib/galaxy/managers/jobs.py:866: error: Unsupported target for indexed assignment ("object") [index] rval["states"][row[0]] = row[1] ``` in mypy. --- lib/galaxy/managers/jobs.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/managers/jobs.py b/lib/galaxy/managers/jobs.py index dd877c582592..e0de23caf429 100644 --- a/lib/galaxy/managers/jobs.py +++ b/lib/galaxy/managers/jobs.py @@ -8,7 +8,9 @@ cast, Dict, List, + Optional, ) +from typing_extensions import TypedDict import sqlalchemy from boltons.iterutils import remap @@ -824,7 +826,14 @@ def merge_states(component_states): return rval -def summarize_jobs_to_dict(sa_session, jobs_source): +class JobsSummary(TypedDict): + populated_state: str + states: Dict[str, int] + model: str + id: int + + +def summarize_jobs_to_dict(sa_session, jobs_source) -> Optional[JobsSummary]: """Produce a summary of jobs for job summary endpoints. :type jobs_source: a Job or ImplicitCollectionJobs or None @@ -833,7 +842,7 @@ def summarize_jobs_to_dict(sa_session, jobs_source): :rtype: dict :returns: dictionary containing job summary information """ - rval = None + rval: Optional[JobsSummary] = None if jobs_source is None: pass elif isinstance(jobs_source, model.Job):