From f03941d1829db497ad5f24eb4dccc71bfcb21c90 Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Thu, 24 Aug 2023 12:28:07 +0200 Subject: [PATCH] [web][typing] add type hints in `task` blueprint --- web/blueprints/task/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/blueprints/task/__init__.py b/web/blueprints/task/__init__.py index 7010011df..74c2bf442 100644 --- a/web/blueprints/task/__init__.py +++ b/web/blueprints/task/__init__.py @@ -32,7 +32,10 @@ nav = BlueprintNavigation(bp, "Tasks", icon='fa-tasks', blueprint_access=access) -def format_parameters(parameters): +T = t.TypeVar("T", bound=t.MutableMapping[str, t.Any]) + + +def format_parameters(parameters: T) -> T: """Make task parameters human readable by looking up objects behind ids""" # Replace building_id by the buildings short name @@ -100,7 +103,7 @@ def task_row(task: UserTask) -> TaskRow: @bp.route("/user//json") -def json_tasks_for_user(user_id) -> ResponseValue: +def json_tasks_for_user(user_id: int) -> ResponseValue: user = get_user_or_404(user_id) return TableResponse[TaskRow]( items=[task_row(t.cast(UserTask, task)) for task in user.tasks] @@ -128,7 +131,7 @@ def json_user_tasks() -> ResponseValue: ).model_dump() -def get_task_or_404(task_id) -> Task | NoReturn: +def get_task_or_404(task_id: int) -> Task | NoReturn: if task := session.session.get(Task, task_id): return task abort(404) @@ -158,7 +161,7 @@ def manually_execute_user_task(task_id: int) -> ResponseValue: @bp.route("//cancel") @access.require('user_change') -def cancel_user_task(task_id) -> ResponseValue: +def cancel_user_task(task_id: int) -> ResponseValue: task = get_task_or_404(task_id) cancel_task(task, current_user) @@ -170,7 +173,7 @@ def cancel_user_task(task_id) -> ResponseValue: @bp.route("//reschedule", methods=['GET', 'POST']) @access.require('user_change') -def reschedule_user_task(task_id) -> ResponseValue: +def reschedule_user_task(task_id: int) -> ResponseValue: task = get_task_or_404(task_id) form = RescheduleTaskForm()