diff --git a/api/advent22_api/core/advent_image.py b/api/advent22_api/core/advent_image.py index 813165d..f170f52 100644 --- a/api/advent22_api/core/advent_image.py +++ b/api/advent22_api/core/advent_image.py @@ -1,7 +1,7 @@ import colorsys import logging from dataclasses import dataclass -from typing import AnyStr, Self, TypeAlias +from typing import Self, cast import numpy as np from PIL import Image as PILImage @@ -11,9 +11,9 @@ from PIL.ImageFont import FreeTypeFont from .config import Config -_RGB: TypeAlias = tuple[int, int, int] -_XY: TypeAlias = tuple[float, float] -_Box: TypeAlias = tuple[int, int, int, int] +type _RGB = tuple[int, int, int] +type _XY = tuple[float, float] +type _Box = tuple[int, int, int, int] _logger = logging.getLogger(__name__) @@ -56,7 +56,7 @@ class AdventImage: async def get_text_box( self, xy: _XY, - text: AnyStr, + text: str, font: FreeTypeFont, anchor: str | None = "mm", **text_kwargs, @@ -95,12 +95,12 @@ class AdventImage: pixel_data = np.asarray(self.img.crop(box)) mean_color: np.ndarray = np.mean(pixel_data, axis=(0, 1)) - return _RGB(mean_color.astype(int)) + return cast(_RGB, mean_color.astype(int)) async def hide_text( self, xy: _XY, - text: AnyStr, + text: str, font: FreeTypeFont, anchor: str | None = "mm", **text_kwargs, @@ -134,8 +134,10 @@ class AdventImage: else: tc_v -= 3 - text_color = colorsys.hsv_to_rgb(tc_h, tc_s, tc_v) - text_color = _RGB(int(val) for val in text_color) + text_color: tuple[int | float, int | float, int | float] = colorsys.hsv_to_rgb( + tc_h, tc_s, tc_v + ) + text_color = cast(_RGB, tuple(int(val) for val in text_color)) # Buchstaben verstecken ImageDraw.Draw(self.img).text( diff --git a/api/advent22_api/core/calendar_config.py b/api/advent22_api/core/calendar_config.py index 6760f09..8745232 100644 --- a/api/advent22_api/core/calendar_config.py +++ b/api/advent22_api/core/calendar_config.py @@ -1,5 +1,4 @@ import tomllib -from typing import TypeAlias import tomli_w from fastapi import Depends @@ -20,7 +19,7 @@ class DoorSaved(BaseModel): y2: int -DoorsSaved: TypeAlias = list[DoorSaved] +type DoorsSaved = list[DoorSaved] class CalendarConfig(BaseModel): diff --git a/api/advent22_api/core/settings.py b/api/advent22_api/core/settings.py index d0d2408..73a27f2 100644 --- a/api/advent22_api/core/settings.py +++ b/api/advent22_api/core/settings.py @@ -1,10 +1,6 @@ -from typing import TypeVar - from pydantic import BaseModel from pydantic_settings import BaseSettings, SettingsConfigDict -T = TypeVar("T") - class Credentials(BaseModel): username: str = "" @@ -71,7 +67,7 @@ class Settings(BaseSettings): # openapi settings ##### - def __dev_value(self, value: T) -> T | None: + def __dev_value[T](self, value: T) -> T | None: if self.production_mode: return None