From a986f00c22ea93a9c64eb873424ff77ee625f930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 19 May 2024 20:30:36 +0300 Subject: [PATCH] Use @decorator in @time_limit decorator to remove function nesting --- plextraktsync/decorators/time_limit.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/plextraktsync/decorators/time_limit.py b/plextraktsync/decorators/time_limit.py index b9b3fa4fe9f..80d9a035104 100644 --- a/plextraktsync/decorators/time_limit.py +++ b/plextraktsync/decorators/time_limit.py @@ -1,22 +1,16 @@ -from functools import wraps - from plextraktsync.config import TRAKT_POST_DELAY from plextraktsync.util.Timer import Timer +from decorator import decorator + timer = Timer(TRAKT_POST_DELAY) -def time_limit(): +@decorator +def time_limit(fn, *args, **kwargs): """ Throttles calls not to be called more often than TRAKT_POST_DELAY """ + timer.wait_if_needed() - def decorator(fn): - @wraps(fn) - def wrapper(*args, **kwargs): - timer.wait_if_needed() - return fn(*args, **kwargs) - - return wrapper - - return decorator + return fn(*args, **kwargs)