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 D3DE781A1F; Wed, 18 Jan 2023 17:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674064474; bh=qLStsnp1c09ct3d/7BhyWPgc2BQvD3hEKg+5/nu2LVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jy+yuz+F60nHF7DHuimyxJNczH8hQ9Oj438HhNSFElxWeXiLIoXXpkyZkbwbLzfZs uRmYYjHLcqva534eRDY21yIsTj2Lg/RN8I3q65JreT0vSmzfhtnYXMvDVQ7G4nYdNu JyCFr1dAMuVqyNFInXaHA7Ub+ZmIkiUkwhBB0EJ0cpIp3w/Wt+nTHpvda9X2/QIVcu 7JzhXzMFuhEGn9SFpIo2R32g5NQDLcCD7IHfHQTvc7Mpj8O38E9SFIeoIH0iC5OlGv D2v6xAwRAcO/6P1HhJXI9KqJAdt/t5xX+/Z42Jk57CF/atS902tG5pGjJOnAdN7dRp dcGJgAHBy/34Q== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 09/17] discord: fix: Fix the type annotations for the decorator Date: Thu, 19 Jan 2023 00:53:48 +0700 Message-Id: <20230118175356.1853-10-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: Previously, these decorators did not use type annotations. In this commit, I have implemented them. Signed-off-by: Muhammad Rizki --- daemon/dscord/gnuweeb/filters.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/daemon/dscord/gnuweeb/filters.py b/daemon/dscord/gnuweeb/filters.py index b342c7a..28b492c 100644 --- a/daemon/dscord/gnuweeb/filters.py +++ b/daemon/dscord/gnuweeb/filters.py @@ -5,7 +5,8 @@ import asyncio -from typing import Any +from typing import Any, Callable, TypeVar, Coroutine +from typing_extensions import ParamSpec, ParamSpecArgs, ParamSpecKwargs from functools import wraps import discord @@ -15,9 +16,13 @@ from dscord import config from logger import BotLogger -def lore_admin(func): +T = TypeVar("T") +P = ParamSpec("P") + + +def lore_admin(func: Callable[P, Coroutine[Any,Any,T]]) -> Callable[P, Coroutine[Any,Any,T]]: @wraps(func) - async def callback(*args: Any, **kwargs: Any) -> Any: + async def callback(*args: ParamSpecArgs, **kwargs: ParamSpecKwargs) -> T: i: "Interaction" = args[1] user_roles = [role.id for role in i.user.roles] @@ -33,12 +38,12 @@ def lore_admin(func): return callback -def wait_on_limit(func): +def wait_on_limit(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 discord.errors.RateLimited as e: # Calling logger attr from the GWClient() class logger = args[0].logger -- Muhammad Rizki