From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [175.158.50.43]) by gnuweeb.org (Postfix) with ESMTPSA id 788247F937; Wed, 18 Jan 2023 17:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674064470; bh=UtJhNP+VA2/BE8whW1V6EmxwUL63m32qSsIqF/eumZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rBY5MtGaVDcNwpQfT4MCChSsyPhNStmfHoSVg/k6yPq4vWO73ZdNq+SawG8aQgrpR NxMK9eveyJsn+NrP5hQ37j9rId4O8mXBAfeGmfT/Qdd1NVW6nhxT7QsWar1aJx4/VP q7fFd4v4DrpFBGF++w3oS/Y19b0Ny8VjCavDGB6pekYIzIljMvv60v3Z55cg3GmHq4 mFQcUV9r5p8i6XJMR0SYNaFs8/p0wDaMKGd46KKbef81m1SPYZ82aVLGJFevRn/MOV wV0gg06YiwoaH602Z5a8lk7WfvNCxWz19bw3kE5oq1XFCspsUbb64NVNj4diQTG05T CzvWG4h52Oyjg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 07/17] telegram: fix: Fix the type annoations for the decorator Date: Thu, 19 Jan 2023 00:53:46 +0700 Message-Id: <20230118175356.1853-8-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230118175356.1853-1-kiizuha@gnuweeb.org> References: <20230118175356.1853-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: In the previous commit, I created a TODO to fix the typing. In this commit, I have fixed the decorator's typing. Fixes: ba02aa3376a4 ("daemon: Add typing in decorator") Signed-off-by: Muhammad Rizki --- daemon/telegram/packages/decorator.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/daemon/telegram/packages/decorator.py b/daemon/telegram/packages/decorator.py index efcfc38..6bfd8bc 100644 --- a/daemon/telegram/packages/decorator.py +++ b/daemon/telegram/packages/decorator.py @@ -4,25 +4,24 @@ # from pyrogram.errors.exceptions.flood_420 import FloodWait -from pyrogram.types import Message -from typing import Any, Callable, TypeVar +from typing import Any, Callable, TypeVar, Coroutine +from typing_extensions import ParamSpec, ParamSpecArgs, ParamSpecKwargs from functools import wraps import re import asyncio __all__ = ["handle_flood"] -T = TypeVar("T", bound=Message) +T = TypeVar("T") +P = ParamSpec("P") -# -# TODO(Muhammad Rizki): Add more typing for @handle_flood -# -def handle_flood(func: Callable[[T], T]) -> Callable[[T], T]: + +def handle_flood(func: Callable[P, Coroutine[Any,Any,T]]) -> Callable[P, Coroutine[Any,Any,T]]: @wraps(func) - async def callback(*args: Any) -> Any: + async def callback(*args: ParamSpecArgs, **kwargs: ParamSpecKwargs) -> T: while True: try: - return await func(*args) + return await func(*args, **kwargs) except FloodWait as e: # Calling logger attr from the DaemonTelegram() class logger = args[0].logger -- Muhammad Rizki