mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2026-02-25 02:20:17 +00:00
🔧 minor refactoring
- use `type` keyword instead of `typing.TypeAlias` - use `str` instead of `AnyStr`
This commit is contained in:
parent
c7679072aa
commit
67eebecd39
3 changed files with 13 additions and 16 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue