From 74688f45b866c7770eca7f7be50e123f804c1ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Fri, 8 Sep 2023 11:27:23 +0000 Subject: [PATCH] typing issues --- api/advent22_api/core/advent_image.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/advent22_api/core/advent_image.py b/api/advent22_api/core/advent_image.py index 8a071a0..4a14774 100644 --- a/api/advent22_api/core/advent_image.py +++ b/api/advent22_api/core/advent_image.py @@ -1,10 +1,13 @@ import colorsys from dataclasses import dataclass -from typing import Self +from typing import Self, TypeAlias, cast import numpy as np from PIL import Image, ImageDraw, ImageFont +_RGB: TypeAlias = tuple[int, int, int] +_XY: TypeAlias = tuple[float, float] + @dataclass(slots=True, frozen=True) class AdventImage: @@ -43,7 +46,7 @@ class AdventImage: async def get_text_box( self, - xy: tuple[float, float], + xy: _XY, text: str | bytes, font: "ImageFont._Font", anchor: str | None = "mm", @@ -81,13 +84,13 @@ class AdventImage: """ pixel_data = self.img.crop(box).getdata() - mean_color: np.ndarray = np.mean(a=pixel_data, axis=0) + mean_color: np.ndarray = np.mean(pixel_data, axis=0) - return tuple(mean_color.astype(int)[:3]) + return cast(_RGB, tuple(mean_color.astype(int))) async def hide_text( self, - xy: tuple[float, float], + xy: _XY, text: str | bytes, font: "ImageFont._Font", anchor: str | None = "mm", @@ -127,7 +130,7 @@ class AdventImage: xy=xy, text=text, font=font, - fill=text_color, + fill=cast(_RGB, text_color), anchor=anchor, **text_kwargs, )