From fe8f12b3d9f6e709ada0f8810e2c3e4a538bfa2c Mon Sep 17 00:00:00 2001 From: japandotorg Date: Sun, 21 Jul 2024 20:39:30 +0530 Subject: [PATCH] [BattleRoyale] use my own type --- battleroyale/models/_pillow.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/battleroyale/models/_pillow.py b/battleroyale/models/_pillow.py index 3e3bd51..12657dc 100644 --- a/battleroyale/models/_pillow.py +++ b/battleroyale/models/_pillow.py @@ -24,15 +24,17 @@ # much of this code has been taken from https://github.com/shahriyardx/easy-pil/tree/master -import io from io import BytesIO +from os import PathLike from pathlib import Path from typing import Any, Dict, Literal, Optional, Tuple, Union -from PIL import Image, ImageDraw, ImageFont, _typing +from PIL import Image, ImageDraw, ImageFont Color = Union[int, str, Tuple[int, int, int], Tuple[int, int, int, int]] +StrOrBytesPath = Union[str, bytes, PathLike[str], PathLike[bytes]] + class Font: def __init__(self, path: str, size: int = 10, **kwargs: Any) -> None: @@ -101,8 +103,8 @@ def __init__(self, _image: Union[Image.Image, str, BytesIO, "Editor", Canvas, Pa self.image: Image.Image = self.image.convert("RGBA") @property - def image_bytes(self) -> io.BytesIO: - _bytes: io.BytesIO = io.BytesIO() + def image_bytes(self) -> BytesIO: + _bytes: BytesIO = BytesIO() self.image.save(_bytes, "png", optimize=True) _bytes.seek(0) return _bytes @@ -111,7 +113,7 @@ def show(self) -> None: self.image.show() def save( - self, fp: _typing.StrOrBytesPath, file_format: Optional[str] = None, **params: Any + self, fp: StrOrBytesPath, file_format: Optional[str] = None, **params: Any ) -> None: self.image.save(fp, file_format, **params)