From 282b3bb8fc4e022e0a289599a8cdedf804defd08 Mon Sep 17 00:00:00 2001 From: laggykiller Date: Tue, 19 Mar 2024 19:32:15 +0800 Subject: [PATCH] Improve typing; Fix random deadlocks esp when using scale_filter=nearest; Add `box` and `hamming` scale_filter --- src/sticker_convert/converter.py | 18 ++--- .../downloaders/download_base.py | 35 +++----- .../downloaders/download_kakao.py | 3 +- .../downloaders/download_line.py | 5 +- .../downloaders/download_signal.py | 3 +- .../downloaders/download_telegram.py | 3 +- src/sticker_convert/gui.py | 2 +- .../gui_components/frames/progress_frame.py | 2 +- .../windows/advanced_compression_window.py | 2 + src/sticker_convert/job.py | 79 ++++++++----------- src/sticker_convert/resources/help.json | 2 +- .../uploaders/compress_wastickers.py | 4 +- src/sticker_convert/uploaders/upload_base.py | 5 +- .../uploaders/upload_signal.py | 6 +- .../uploaders/upload_telegram.py | 4 +- .../uploaders/xcode_imessage.py | 4 +- .../utils/auth/get_kakao_auth.py | 2 +- src/sticker_convert/utils/callback.py | 12 ++- .../utils/files/metadata_handler.py | 2 +- .../utils/media/format_verify.py | 2 +- 20 files changed, 83 insertions(+), 112 deletions(-) diff --git a/src/sticker_convert/converter.py b/src/sticker_convert/converter.py index 95cedda0..eb9ddff7 100755 --- a/src/sticker_convert/converter.py +++ b/src/sticker_convert/converter.py @@ -6,13 +6,13 @@ from math import ceil, floor from pathlib import Path from queue import Queue -from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Union, cast +from typing import TYPE_CHECKING, Any, List, Literal, Optional, Tuple, Union, cast import numpy as np from PIL import Image from sticker_convert.job_option import CompOption -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.cache_store import CacheStore from sticker_convert.utils.media.codec_info import CodecInfo from sticker_convert.utils.media.format_verify import FormatVerify @@ -20,12 +20,6 @@ if TYPE_CHECKING: from av.video.plane import VideoPlane # type: ignore -CbQueueItemType = Union[ - Tuple[str, Optional[Tuple[str]], Optional[Dict[str, str]]], - str, - None, -] - MSG_START_COMP = "[I] Start compressing {} -> {}" MSG_SKIP_COMP = "[S] Compatible file found, skip compress and just copy {} -> {}" MSG_COMP = ( @@ -89,7 +83,7 @@ def __init__( opt_comp: CompOption, cb: "Union[Queue[CbQueueItemType], Callback]", # cb_return: CallbackReturn - ): + ) -> None: self.in_f: Union[bytes, Path] if isinstance(in_f, Path): self.in_f = in_f @@ -514,11 +508,15 @@ def frames_resize( ) -> "List[np.ndarray[Any, Any]]": frames_out: "List[np.ndarray[Any, Any]]" = [] - resample: Literal[0, 1, 2, 3] + resample: Literal[0, 1, 2, 3, 4, 5] if self.opt_comp.scale_filter == "nearest": resample = Image.NEAREST + elif self.opt_comp.scale_filter == "box": + resample = Image.BOX elif self.opt_comp.scale_filter == "bilinear": resample = Image.BILINEAR + elif self.opt_comp.scale_filter == "hamming": + resample = Image.HAMMING elif self.opt_comp.scale_filter == "bicubic": resample = Image.BICUBIC elif self.opt_comp.scale_filter == "lanczos": diff --git a/src/sticker_convert/downloaders/download_base.py b/src/sticker_convert/downloaders/download_base.py index c8b74d9e..285045eb 100755 --- a/src/sticker_convert/downloaders/download_base.py +++ b/src/sticker_convert/downloaders/download_base.py @@ -3,12 +3,12 @@ from pathlib import Path from queue import Queue -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Any, List, Optional, Tuple, Union import requests from sticker_convert.job_option import CredOption -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType class DownloadBase: @@ -18,35 +18,20 @@ def __init__( out_dir: Path, opt_cred: Optional[CredOption], cb: Union[ - Queue[ - Union[ - Tuple[str, Optional[Tuple[str]], Optional[Dict[str, Any]]], - str, - None, - ] - ], + Queue[CbQueueItemType], Callback, ], cb_return: CallbackReturn, - ): - self.url: str = url - self.out_dir: Path = out_dir - self.opt_cred: Optional[CredOption] = opt_cred - self.cb: Union[ - Queue[ - Union[ - Tuple[str, Optional[Tuple[str]], Optional[Dict[str, Any]]], - str, - None, - ] - ], - Callback, - ] = cb - self.cb_return: CallbackReturn = cb_return + ) -> None: + self.url = url + self.out_dir = out_dir + self.opt_cred = opt_cred + self.cb = cb + self.cb_return = cb_return def download_multiple_files( self, targets: List[Tuple[str, Path]], retries: int = 3, **kwargs: Any - ): + ) -> None: # targets format: [(url1, dest2), (url2, dest2), ...] self.cb.put( ("bar", None, {"set_progress_mode": "determinate", "steps": len(targets)}) diff --git a/src/sticker_convert/downloaders/download_kakao.py b/src/sticker_convert/downloaders/download_kakao.py index 48bc224f..be1ba6da 100755 --- a/src/sticker_convert/downloaders/download_kakao.py +++ b/src/sticker_convert/downloaders/download_kakao.py @@ -13,10 +13,9 @@ from bs4 import BeautifulSoup from bs4.element import Tag -from sticker_convert.converter import CbQueueItemType from sticker_convert.downloaders.download_base import DownloadBase from sticker_convert.job_option import CredOption -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.media.decrypt_kakao import DecryptKakao diff --git a/src/sticker_convert/downloaders/download_line.py b/src/sticker_convert/downloaders/download_line.py index 4ffff948..861addd1 100755 --- a/src/sticker_convert/downloaders/download_line.py +++ b/src/sticker_convert/downloaders/download_line.py @@ -15,11 +15,10 @@ from bs4 import BeautifulSoup from PIL import Image -from sticker_convert.converter import CbQueueItemType from sticker_convert.downloaders.download_base import DownloadBase from sticker_convert.job_option import CredOption from sticker_convert.utils.auth.get_line_auth import GetLineAuth -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.media.apple_png_normalize import ApplePngNormalize @@ -227,7 +226,7 @@ def decompress( num: int, prefix: str = "", suffix: str = "", - ): + ) -> None: data = zf.read(f_path) ext = Path(f_path).suffix if ext == ".png" and not self.is_emoji and int() < 775: diff --git a/src/sticker_convert/downloaders/download_signal.py b/src/sticker_convert/downloaders/download_signal.py index af6139ae..5c13fa60 100755 --- a/src/sticker_convert/downloaders/download_signal.py +++ b/src/sticker_convert/downloaders/download_signal.py @@ -8,10 +8,9 @@ from signalstickers_client.errors import SignalException # type: ignore from signalstickers_client.models import StickerPack # type: ignore -from sticker_convert.converter import CbQueueItemType from sticker_convert.downloaders.download_base import DownloadBase from sticker_convert.job_option import CredOption -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.media.codec_info import CodecInfo diff --git a/src/sticker_convert/downloaders/download_telegram.py b/src/sticker_convert/downloaders/download_telegram.py index c7b6ce88..510ea06b 100755 --- a/src/sticker_convert/downloaders/download_telegram.py +++ b/src/sticker_convert/downloaders/download_telegram.py @@ -8,10 +8,9 @@ from telegram import Bot from telegram.error import TelegramError -from sticker_convert.converter import CbQueueItemType from sticker_convert.downloaders.download_base import DownloadBase from sticker_convert.job_option import CredOption -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import MetadataHandler diff --git a/src/sticker_convert/gui.py b/src/sticker_convert/gui.py index 31ab733a..4f2257db 100755 --- a/src/sticker_convert/gui.py +++ b/src/sticker_convert/gui.py @@ -641,7 +641,7 @@ def cb_bar( steps: int = 0, update_bar: bool = False, **kwargs: Any, - ): + ) -> None: with self.bar_lock: self.progress_frame.update_progress_bar( set_progress_mode, steps, update_bar, *args, **kwargs diff --git a/src/sticker_convert/gui_components/frames/progress_frame.py b/src/sticker_convert/gui_components/frames/progress_frame.py index 6cd17b3d..8cfdb6f3 100644 --- a/src/sticker_convert/gui_components/frames/progress_frame.py +++ b/src/sticker_convert/gui_components/frames/progress_frame.py @@ -36,7 +36,7 @@ def update_progress_bar( set_progress_mode: Optional[str] = None, steps: int = 0, update_bar: bool = False, - ): + ) -> None: if update_bar and self.progress_bar_cli: self.progress_bar_cli.update() self.progress_bar["value"] += 100 / self.progress_bar_steps diff --git a/src/sticker_convert/gui_components/windows/advanced_compression_window.py b/src/sticker_convert/gui_components/windows/advanced_compression_window.py index 37fd0cd7..9b70e3ca 100644 --- a/src/sticker_convert/gui_components/windows/advanced_compression_window.py +++ b/src/sticker_convert/gui_components/windows/advanced_compression_window.py @@ -329,7 +329,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.gui.scale_filter_var, self.gui.scale_filter_var.get(), "nearest", + "box", "bilinear", + "hamming", "bicubic", "lanczos", bootstyle="secondary", # type: ignore diff --git a/src/sticker_convert/job.py b/src/sticker_convert/job.py index da16fc24..4e030e86 100755 --- a/src/sticker_convert/job.py +++ b/src/sticker_convert/job.py @@ -7,11 +7,11 @@ import traceback from datetime import datetime from multiprocessing import Process, Value -from multiprocessing.managers import SyncManager +from multiprocessing.managers import SyncManager, ListProxy from pathlib import Path from queue import Queue from threading import Thread -from typing import Any, Callable, Dict, Generator, Iterator, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, Generator, Iterator, List, Optional, Tuple from urllib.parse import urlparse from sticker_convert.converter import StickerConvert @@ -24,11 +24,13 @@ from sticker_convert.uploaders.upload_signal import UploadSignal from sticker_convert.uploaders.upload_telegram import UploadTelegram from sticker_convert.uploaders.xcode_imessage import XcodeImessage -from sticker_convert.utils.callback import CallbackReturn +from sticker_convert.utils.callback import CallbackReturn, CbQueueItemType from sticker_convert.utils.files.json_resources_loader import OUTPUT_JSON from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.media.codec_info import CodecInfo +CbQueueType = Queue[CbQueueItemType] +WorkListType = ListProxy[Optional[Tuple[Callable[..., Any], Tuple[Any, ...]]]] class Executor: def __init__( @@ -38,7 +40,7 @@ def __init__( cb_bar: Callable[..., None], cb_ask_bool: Callable[..., bool], cb_ask_str: Callable[..., str], - ): + ) -> None: self.cb_msg = cb_msg self.cb_msg_block = cb_msg_block self.cb_bar = cb_bar @@ -47,19 +49,11 @@ def __init__( self.manager = SyncManager() self.manager.start() - self.work_queue: Queue[Optional[Tuple[Callable[..., Any], Tuple[Any, ...]]]] = ( - self.manager.Queue() - ) + # Using list instead of queue for work_list as it can cause random deadlocks + # Especially when using scale_filter=nearest + self.work_list: WorkListType = self.manager.list() self.results_queue: Queue[Any] = self.manager.Queue() - self.cb_queue: Queue[ - Union[ - Tuple[ - Optional[str], Optional[Tuple[Any, ...]], Optional[Dict[str, str]] - ], - str, - None, - ] - ] = self.manager.Queue() + self.cb_queue: CbQueueType = self.manager.Queue() self.cb_return = CallbackReturn() self.processes: List[Process] = [] @@ -76,16 +70,9 @@ def __init__( def cb_thread( self, - cb_queue: Queue[ - Union[ - Tuple[ - Optional[str], Optional[Tuple[Any, ...]], Optional[Dict[str, str]] - ], - str, - ] - ], + cb_queue: CbQueueType, cb_return: CallbackReturn, - ): + ) -> None: for i in iter(cb_queue.get, None): if isinstance(i, tuple): action = i[0] @@ -118,19 +105,17 @@ def cb_thread( @staticmethod def worker( - work_queue: Queue[Optional[Tuple[Callable[..., Any], Tuple[Any, ...]]]], + work_list: WorkListType, results_queue: Queue[Any], - cb_queue: Queue[ - Union[ - Tuple[ - Optional[str], Optional[Tuple[Any, ...]], Optional[Dict[str, str]] - ], - str, - ] - ], + cb_queue: CbQueueType, cb_return: CallbackReturn, - ): - for work_func, work_args in iter(work_queue.get, None): + ) -> None: + while True: + work = work_list.pop(0) + if work is None: + break + else: + work_func, work_args = work try: results = work_func(*work_args, cb_queue, cb_return) results_queue.put(results) @@ -147,18 +132,17 @@ def worker( e += traceback.format_exc() e += "#####################" cb_queue.put(e) - work_queue.put(None) + work_list.append(None) def start_workers(self, processes: int = 1) -> None: # Would contain None from previous run - while not self.work_queue.empty(): - self.work_queue.get() + self.work_list = self.manager.list() for _ in range(processes): process = Process( target=Executor.worker, args=( - self.work_queue, + self.work_list, self.results_queue, self.cb_queue, self.cb_return, @@ -172,10 +156,10 @@ def start_workers(self, processes: int = 1) -> None: def add_work( self, work_func: Callable[..., Any], work_args: Tuple[Any, ...] ) -> None: - self.work_queue.put((work_func, work_args)) + self.work_list.append((work_func, work_args)) def join_workers(self) -> None: - self.work_queue.put(None) + self.work_list.append(None) try: for process in self.processes: process.join() @@ -188,8 +172,7 @@ def join_workers(self) -> None: def kill_workers(self, *_: Any, **__: Any) -> None: self.is_cancel_job.value = 1 # type: ignore - while not self.work_queue.empty(): - self.work_queue.get() + self.work_list = self.manager.list() for process in self.processes: if platform.system() == "Windows": @@ -213,7 +196,7 @@ def cb( action: Optional[str], args: Optional[Tuple[str, ...]] = None, kwargs: Optional[Dict[str, Any]] = None, - ): + ) -> None: self.cb_queue.put((action, args, kwargs)) @@ -229,7 +212,7 @@ def __init__( cb_bar: Callable[..., None], cb_ask_bool: Callable[..., bool], cb_ask_str: Callable[..., str], - ): + ) -> None: self.opt_input = opt_input self.opt_comp = opt_comp self.opt_output = opt_output @@ -402,7 +385,9 @@ def verify_input(self) -> bool: if self.opt_comp.scale_filter not in ( "nearest", + "box", "bilinear", + "hamming", "bicubic", "lanczos", ): @@ -410,7 +395,7 @@ def verify_input(self) -> bool: error_msg += ( f"[X] scale_filter {self.opt_comp.scale_filter} is not valid option" ) - error_msg += " Valid options: nearest, bilinear, bicubic, lanczos" + error_msg += " Valid options: nearest, box, bilinear, hamming, bicubic, lanczos" if self.opt_comp.quantize_method not in ("imagequant", "fastoctree", "none"): error_msg += "\n" diff --git a/src/sticker_convert/resources/help.json b/src/sticker_convert/resources/help.json index af0bac57..4cb9cf98 100644 --- a/src/sticker_convert/resources/help.json +++ b/src/sticker_convert/resources/help.json @@ -45,7 +45,7 @@ "vid_format": "Set file format if input is animated.", "img_format": "Set file format if input is static.", "fake_vid": "Convert (faking) image to video.\nUseful if:\n(1) Size limit for video is larger than image;\n(2) Mix image and video into same pack.", - "scale_filter": "Set scale filter. Default as lanczos. Valid options are:\n- nearest = Use nearest neighbour (Suitable for pixel art)\n- bilinear = linear interpolation\n- bicubic = Cubic spline interpolation\n- lanczos = A high-quality downsampling filter", + "scale_filter": "Set scale filter. Default as lanczos. Valid options are:\n- nearest = Use nearest neighbour (Suitable for pixel art)\n-box = Similar to nearest, but better downscaling\n- bilinear = Linear interpolation\n- hamming = Similar to bilinear, but better downscaling\n- bicubic = Cubic spline interpolation\n- lanczos = A high-quality downsampling filter", "quantize_method": "Set method for quantizing image. Default as imagequant. Valid options are:\n- imagequant = Best quality but slow\n- fastoctree = Fast but image looks chunky\n- none = No image quantizing, large image size as result", "cache_dir": "Set custom cache directory.\nUseful for debugging, or speed up conversion if cache_dir is on RAM disk.", "default_emoji": "Set the default emoji for uploading Signal and Telegram sticker packs." diff --git a/src/sticker_convert/uploaders/compress_wastickers.py b/src/sticker_convert/uploaders/compress_wastickers.py index cbf2f99e..550bb76e 100755 --- a/src/sticker_convert/uploaders/compress_wastickers.py +++ b/src/sticker_convert/uploaders/compress_wastickers.py @@ -6,10 +6,10 @@ from queue import Queue from typing import Any, List, Union -from sticker_convert.converter import CbQueueItemType, StickerConvert +from sticker_convert.converter import StickerConvert from sticker_convert.job_option import CompOption, CredOption, OutputOption from sticker_convert.uploaders.upload_base import UploadBase -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.cache_store import CacheStore from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.files.sanitize_filename import sanitize_filename diff --git a/src/sticker_convert/uploaders/upload_base.py b/src/sticker_convert/uploaders/upload_base.py index 236c9e1a..c6621a7c 100755 --- a/src/sticker_convert/uploaders/upload_base.py +++ b/src/sticker_convert/uploaders/upload_base.py @@ -2,9 +2,8 @@ from queue import Queue from typing import Union -from sticker_convert.converter import CbQueueItemType from sticker_convert.job_option import CompOption, CredOption, OutputOption -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType class UploadBase: @@ -15,7 +14,7 @@ def __init__( opt_cred: CredOption, cb: "Union[Queue[CbQueueItemType], Callback]", cb_return: CallbackReturn, - ): + ) -> None: if not cb: cb = Callback(silent=True) cb_return = CallbackReturn() diff --git a/src/sticker_convert/uploaders/upload_signal.py b/src/sticker_convert/uploaders/upload_signal.py index e91602c5..9a7185fc 100755 --- a/src/sticker_convert/uploaders/upload_signal.py +++ b/src/sticker_convert/uploaders/upload_signal.py @@ -9,10 +9,10 @@ from signalstickers_client.errors import SignalException # type: ignore from signalstickers_client.models import LocalStickerPack, Sticker # type: ignore -from sticker_convert.converter import CbQueueItemType, StickerConvert +from sticker_convert.converter import StickerConvert from sticker_convert.job_option import CompOption, CredOption, OutputOption from sticker_convert.uploaders.upload_base import UploadBase -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.media.codec_info import CodecInfo from sticker_convert.utils.media.format_verify import FormatVerify @@ -49,7 +49,7 @@ async def upload_pack(pack: LocalStickerPack, uuid: str, password: str) -> str: def add_stickers_to_pack( self, pack: LocalStickerPack, stickers: List[Path], emoji_dict: Dict[str, str] - ): + ) -> None: for src in stickers: self.cb.put(f"Verifying {src} for uploading to signal") diff --git a/src/sticker_convert/uploaders/upload_telegram.py b/src/sticker_convert/uploaders/upload_telegram.py index b9b220c7..1e6eb4a2 100755 --- a/src/sticker_convert/uploaders/upload_telegram.py +++ b/src/sticker_convert/uploaders/upload_telegram.py @@ -9,10 +9,10 @@ from telegram import Bot, InputSticker, Sticker from telegram.error import TelegramError -from sticker_convert.converter import CbQueueItemType, StickerConvert +from sticker_convert.converter import StickerConvert from sticker_convert.job_option import CompOption, CredOption, OutputOption from sticker_convert.uploaders.upload_base import UploadBase -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import MetadataHandler from sticker_convert.utils.media.format_verify import FormatVerify diff --git a/src/sticker_convert/uploaders/xcode_imessage.py b/src/sticker_convert/uploaders/xcode_imessage.py index df7b5e7f..7494c50c 100755 --- a/src/sticker_convert/uploaders/xcode_imessage.py +++ b/src/sticker_convert/uploaders/xcode_imessage.py @@ -9,11 +9,11 @@ from queue import Queue from typing import Any, Dict, List, Union -from sticker_convert.converter import CbQueueItemType, StickerConvert +from sticker_convert.converter import StickerConvert from sticker_convert.definitions import ROOT_DIR from sticker_convert.job_option import CompOption, CredOption, OutputOption from sticker_convert.uploaders.upload_base import UploadBase -from sticker_convert.utils.callback import Callback, CallbackReturn +from sticker_convert.utils.callback import Callback, CallbackReturn, CbQueueItemType from sticker_convert.utils.files.metadata_handler import XCODE_IMESSAGE_ICONSET, MetadataHandler from sticker_convert.utils.files.sanitize_filename import sanitize_filename from sticker_convert.utils.media.codec_info import CodecInfo diff --git a/src/sticker_convert/utils/auth/get_kakao_auth.py b/src/sticker_convert/utils/auth/get_kakao_auth.py index a472140c..1cd3f5d0 100755 --- a/src/sticker_convert/utils/auth/get_kakao_auth.py +++ b/src/sticker_convert/utils/auth/get_kakao_auth.py @@ -17,7 +17,7 @@ def __init__( cb_msg: Callable[..., None] = print, cb_msg_block: Callable[..., Any] = input, cb_ask_str: Callable[..., str] = input, - ): + ) -> None: self.username = opt_cred.kakao_username self.password = opt_cred.kakao_password self.country_code = opt_cred.kakao_country_code diff --git a/src/sticker_convert/utils/callback.py b/src/sticker_convert/utils/callback.py index 74d4f5f3..59297135 100644 --- a/src/sticker_convert/utils/callback.py +++ b/src/sticker_convert/utils/callback.py @@ -4,6 +4,12 @@ from tqdm import tqdm +CbQueueTupleType = Tuple[Optional[str], Optional[Tuple[Any, ...]], Optional[Dict[str, Any]]] +CbQueueItemType = Union[ + CbQueueTupleType, + str, + None, +] class CallbackReturn: def __init__(self) -> None: @@ -34,7 +40,7 @@ def __init__( ask_str: Optional[Callable[..., str]] = None, silent: bool = False, no_confirm: bool = False, - ): + ) -> None: self.progress_bar: Optional[tqdm[Any]] = None if msg: @@ -88,7 +94,7 @@ def cb_bar( set_progress_mode: Optional[str] = None, steps: int = 0, update_bar: bool = False, - ): + ) -> None: if self.silent: return @@ -154,7 +160,7 @@ def cb_ask_str( def put( self, i: Union[ - Tuple[Optional[str], Optional[Tuple[Any, ...]], Optional[Dict[str, Any]]], + CbQueueItemType, str, ], ) -> Union[str, bool, None]: diff --git a/src/sticker_convert/utils/files/metadata_handler.py b/src/sticker_convert/utils/files/metadata_handler.py index 7ff5d380..a0e3fad3 100755 --- a/src/sticker_convert/utils/files/metadata_handler.py +++ b/src/sticker_convert/utils/files/metadata_handler.py @@ -133,7 +133,7 @@ def set_metadata( title: Optional[str] = None, author: Optional[str] = None, emoji_dict: Optional[Dict[str, str]] = None, - ): + ) -> None: title_path = Path(directory, "title.txt") if title is not None: with open(title_path, "w+", encoding="utf-8") as f: diff --git a/src/sticker_convert/utils/media/format_verify.py b/src/sticker_convert/utils/media/format_verify.py index d59dfc39..e689bee5 100755 --- a/src/sticker_convert/utils/media/format_verify.py +++ b/src/sticker_convert/utils/media/format_verify.py @@ -162,7 +162,7 @@ def check_format( file: Union[Path, bytes], fmt: Tuple[Tuple[str, ...], Tuple[str, ...]], file_info: Optional[CodecInfo] = None, - ): + ) -> bool: if file_info: file_animated = file_info.is_animated file_ext = file_info.file_ext