From 4627efe3248bfaef61a8bc897cc14a3bafd444f6 Mon Sep 17 00:00:00 2001 From: "Leonhard S." Date: Mon, 4 Nov 2024 16:01:53 +0100 Subject: [PATCH] Fix deprecation warnings for utc shorthands --- auraxium/_proxy.py | 10 +++++----- auraxium/event/_trigger.py | 2 +- auraxium/models/base.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auraxium/_proxy.py b/auraxium/_proxy.py index dcdee52..c55163e 100644 --- a/auraxium/_proxy.py +++ b/auraxium/_proxy.py @@ -56,8 +56,8 @@ def __init__(self, type_: Type[_Ps2ObjectT], query: Query, self._data: List[_Ps2ObjectT] self._index: int self._lock = asyncio.Lock() - self._last_fetched = datetime.datetime.utcfromtimestamp(0) - max_age = datetime.datetime.utcnow() - self._last_fetched + self._last_fetched = datetime.datetime.fromtimestamp(0, datetime.UTC) + max_age = datetime.datetime.now(datetime.UTC) - self._last_fetched assert self._ttu < max_age.total_seconds() async def _poll(self) -> None: @@ -70,7 +70,7 @@ async def _poll(self) -> None: payload = await self._client.request(self.query) list_ = self._resolve_nested_payload(payload) self._data = [self._type(d, client=self._client) for d in list_] - self._last_fetched = datetime.datetime.utcnow() + self._last_fetched = datetime.datetime.now(datetime.UTC) def _resolve_nested_payload(self, payload: CensusData) -> List[CensusData]: """Resolve the object payload. @@ -143,7 +143,7 @@ def __aiter__(self) -> 'SequenceProxy[_Ps2ObjectT]': return self async def __anext__(self) -> _Ps2ObjectT: - age = datetime.datetime.utcnow() - self._last_fetched + age = datetime.datetime.now(datetime.UTC) - self._last_fetched if age.total_seconds() > self._ttu: if self._index > -1: warnings.warn('Data went stale during iteration, polling new') @@ -181,7 +181,7 @@ async def resolve(self) -> Optional[_Ps2ObjectT]: :return: The object, or :obj:`None` if no match was found. """ - age = datetime.datetime.utcnow() - self._last_fetched + age = datetime.datetime.now(datetime.UTC) - self._last_fetched if age.total_seconds() > self._ttu: await self._poll() try: diff --git a/auraxium/event/_trigger.py b/auraxium/event/_trigger.py index e560794..b0df411 100644 --- a/auraxium/event/_trigger.py +++ b/auraxium/event/_trigger.py @@ -226,7 +226,7 @@ async def run(self, event: Event) -> None: :param Event event: The event to pass to the trigger action. """ - self.last_run = datetime.datetime.utcnow() + self.last_run = datetime.datetime.now(datetime.UTC) if self.action is None: # pragma: no cover warnings.warn(f'Trigger {self.name} run with no action specified') return diff --git a/auraxium/models/base.py b/auraxium/models/base.py index 315305b..d94c37f 100644 --- a/auraxium/models/base.py +++ b/auraxium/models/base.py @@ -139,12 +139,12 @@ def _utc_from_timestamp(cls, value: str, ) -> datetime.datetime: """Convert timestamps to UTC datetimes.""" _ = info - return datetime.datetime.utcfromtimestamp(int(value)) + return datetime.datetime.fromtimestamp(int(value), datetime.UTC) @property def age(self) -> float: """The age of the event in seconds.""" - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.UTC) return (now - self.timestamp).total_seconds()