mirror of
https://github.com/Casvt/MIND.git
synced 2026-04-03 03:00:22 -04:00
Improved type hinting in api.py
This commit is contained in:
@@ -9,9 +9,11 @@ from __future__ import annotations
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import (TYPE_CHECKING, Any, Dict, List, Literal,
|
||||
from typing import (TYPE_CHECKING, Any, Callable, Dict, List, Literal,
|
||||
Sequence, Tuple, TypedDict, TypeVar, Union, cast)
|
||||
|
||||
from flask import Response
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from backend.implementations.users import User
|
||||
|
||||
@@ -21,16 +23,23 @@ T = TypeVar('T')
|
||||
U = TypeVar('U')
|
||||
WEEKDAY_NUMBER = Literal[0, 1, 2, 3, 4, 5, 6]
|
||||
|
||||
BaseSerialisable = Union[
|
||||
BaseJSONSerialisable = Union[
|
||||
int, float, bool, str, None, TypedDict
|
||||
]
|
||||
Serialisable = Union[
|
||||
JSONSerialisable = Union[
|
||||
BaseJSONSerialisable,
|
||||
TypedDict,
|
||||
Sequence[BaseSerialisable],
|
||||
Sequence[Dict[str, BaseSerialisable]],
|
||||
Dict[str, BaseSerialisable],
|
||||
Dict[str, Sequence[BaseSerialisable]],
|
||||
Dict[str, Dict[str, BaseSerialisable]]
|
||||
Sequence["JSONSerialisable"],
|
||||
Dict[str, "JSONSerialisable"]
|
||||
]
|
||||
EndpointResponse = Union[
|
||||
Tuple[Dict[str, JSONSerialisable], int],
|
||||
Tuple[Response, int],
|
||||
None
|
||||
]
|
||||
EndpointHandler = Union[
|
||||
Callable[[Dict[str, Any]], EndpointResponse],
|
||||
Callable[[Dict[str, Any], int], EndpointResponse]
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ from cron_converter import Cron
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from backend.base.definitions import (WEEKDAY_NUMBER, GeneralReminderData,
|
||||
RepeatQuantity, SendResult,
|
||||
Serialisable, T, U)
|
||||
JSONSerialisable, RepeatQuantity,
|
||||
SendResult, T, U)
|
||||
from backend.base.logging import LOGGER
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ def current_thread_id() -> int:
|
||||
|
||||
|
||||
def return_api(
|
||||
result: Serialisable,
|
||||
result: JSONSerialisable,
|
||||
error: Union[str, None] = None,
|
||||
code: int = 200
|
||||
) -> Tuple[Dict[str, Any], int]:
|
||||
|
||||
Reference in New Issue
Block a user