From: Daniele Varrazzo Date: Sun, 8 Oct 2023 09:45:28 +0000 (+0200) Subject: refactor(pool): define scheduler task as dataclass X-Git-Tag: pool-3.2.0~12^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fa8a00e7fcd12e93848113d903948f7a3549c40;p=thirdparty%2Fpsycopg.git refactor(pool): define scheduler task as dataclass --- diff --git a/psycopg_pool/psycopg_pool/_task.py b/psycopg_pool/psycopg_pool/_task.py index 419765014..9169f759c 100644 --- a/psycopg_pool/psycopg_pool/_task.py +++ b/psycopg_pool/psycopg_pool/_task.py @@ -4,24 +4,11 @@ Task for Scheduler and AsyncScheduler # Copyright (C) 2023 The Psycopg Team -from typing import Any, Callable, Optional, NamedTuple +from typing import Any, Callable, Optional +from dataclasses import dataclass, field -class Task(NamedTuple): +@dataclass(order=True) +class Task: time: float - action: Optional[Callable[[], Any]] - - def __eq__(self, other: "Task") -> Any: # type: ignore[override] - return self.time == other.time - - def __lt__(self, other: "Task") -> Any: # type: ignore[override] - return self.time < other.time - - def __le__(self, other: "Task") -> Any: # type: ignore[override] - return self.time <= other.time - - def __gt__(self, other: "Task") -> Any: # type: ignore[override] - return self.time > other.time - - def __ge__(self, other: "Task") -> Any: # type: ignore[override] - return self.time >= other.time + action: Optional[Callable[[], Any]] = field(compare=False)