From def5f18272506d61ff8a1a833b842aff6fb7a7e9 Mon Sep 17 00:00:00 2001 From: "Leonhard S." Date: Mon, 4 Nov 2024 16:01:53 +0100 Subject: [PATCH 1/3] Fix deprecation warnings for utc shorthands --- auraxium/_proxy.py | 12 +++++++----- auraxium/event/_trigger.py | 2 +- auraxium/models/base.py | 4 ++-- auraxium/ps2/_world.py | 3 ++- tests/unit/trigger_test.py | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/auraxium/_proxy.py b/auraxium/_proxy.py index dcdee52..62d67ba 100644 --- a/auraxium/_proxy.py +++ b/auraxium/_proxy.py @@ -56,8 +56,10 @@ 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.timezone.utc) + max_age = datetime.datetime.now( + datetime.timezone.utc) - self._last_fetched assert self._ttu < max_age.total_seconds() async def _poll(self) -> None: @@ -70,7 +72,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.timezone.utc) def _resolve_nested_payload(self, payload: CensusData) -> List[CensusData]: """Resolve the object payload. @@ -143,7 +145,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.timezone.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 +183,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.timezone.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..5e678d7 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.timezone.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..e41d604 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.timezone.utc) @property def age(self) -> float: """The age of the event in seconds.""" - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) return (now - self.timestamp).total_seconds() diff --git a/auraxium/ps2/_world.py b/auraxium/ps2/_world.py index 400c52a..cacd2a7 100644 --- a/auraxium/ps2/_world.py +++ b/auraxium/ps2/_world.py @@ -122,4 +122,5 @@ async def status(self) -> Tuple[str, datetime.datetime]: data = extract_single(payload, 'game_server_status') status = str(data['last_reported_state']) last_updated = int(str(data['last_reported_time'])) - return status, datetime.datetime.utcfromtimestamp(last_updated) + return status, datetime.datetime.fromtimestamp( + last_updated, datetime.timezone.utc) diff --git a/tests/unit/trigger_test.py b/tests/unit/trigger_test.py index 05916a0..1b4ea59 100644 --- a/tests/unit/trigger_test.py +++ b/tests/unit/trigger_test.py @@ -11,7 +11,7 @@ class TriggerTest(unittest.TestCase): """Test cases for the auraxium.event.Trigger class.""" - time = datetime.datetime.utcnow() + time = datetime.datetime.now(datetime.timezone.utc) @classmethod def death_evt_factory(cls, attacker: int, victim: int, world: int, From bb2455f24bb14a0f1e661694c197ddabbea2947d Mon Sep 17 00:00:00 2001 From: "Leonhard S." Date: Mon, 4 Nov 2024 16:53:09 +0100 Subject: [PATCH 2/3] Remove class properties --- auraxium/census/_support.py | 89 +++++++++++++------------------------ 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/auraxium/census/_support.py b/auraxium/census/_support.py index 56fb718..7b96637 100644 --- a/auraxium/census/_support.py +++ b/auraxium/census/_support.py @@ -34,7 +34,6 @@ class SearchModifier(enum.Enum): GREATER_THAN_OR_EQUAL: ']', STARTS_WITH: '^', CONTAINS: '*', NOT_EQUAL: '!' """ - # pylint: disable=invalid-name EQUAL_TO = 0 LESS_THAN = 1 @@ -45,77 +44,53 @@ class SearchModifier(enum.Enum): CONTAINS = 6 NOT_EQUAL = 7 - @classmethod - @property - def EQ(cls) -> 'SearchModifier': - """Alias for :class:`EQUAL_TO `. + EQ = EQUAL_TO + """Alias for :class:`EQUAL_TO `. - .. versionadded:: 0.2 - """ - return cls.EQUAL_TO + .. versionadded:: 0.2 + """ - @classmethod - @property - def LT(cls) -> 'SearchModifier': - """Alias for :class:`LESS_THAN `. + LT = LESS_THAN + """Alias for :class:`LESS_THAN `. - .. versionadded:: 0.2 - """ - return cls.LESS_THAN + .. versionadded:: 0.2 + """ - @classmethod - @property - def LTE(cls) -> 'SearchModifier': - """Alias for :class:`LESS_THAN_OR_EQUAL `. + LTE = LESS_THAN_OR_EQUAL + """Alias for :class:`LESS_THAN_OR_EQUAL `. - .. versionadded:: 0.2 - """ - return cls.LESS_THAN_OR_EQUAL + .. versionadded:: 0.2 + """ - @classmethod - @property - def GT(cls) -> 'SearchModifier': - """Alias for :class:`GREATER_THAN `. + GT = GREATER_THAN + """Alias for :class:`GREATER_THAN `. - .. versionadded:: 0.2 - """ - return cls.GREATER_THAN + .. versionadded:: 0.2 + """ - @classmethod - @property - def GTE(cls) -> 'SearchModifier': - """Alias for :class:`GREATER_THAN_OR_EQUAL `. + GTE = GREATER_THAN_OR_EQUAL + """Alias for :class:`GREATER_THAN_OR_EQUAL `. - .. versionadded:: 0.2 - """ - return cls.GREATER_THAN_OR_EQUAL + .. versionadded:: 0.2 + """ - @classmethod - @property - def SW(cls) -> 'SearchModifier': - """Alias for :class:`STARTS_WITH `. + SW = STARTS_WITH + """Alias for :class:`STARTS_WITH `. - .. versionadded:: 0.2 - """ - return cls.STARTS_WITH + .. versionadded:: 0.2 + """ - @classmethod - @property - def IN(cls) -> 'SearchModifier': - """Alias for :class:`CONTAINS `. + IN = CONTAINS + """Alias for :class:`CONTAINS `. - .. versionadded:: 0.2 - """ - return cls.CONTAINS + .. versionadded:: 0.2 + """ - @classmethod - @property - def NE(cls) -> 'SearchModifier': - """Alias for :class:`NOT_EQUAL `. + NE = NOT_EQUAL + """Alias for :class:`NOT_EQUAL `. - .. versionadded:: 0.2 - """ - return cls.NOT_EQUAL + .. versionadded:: 0.2 + """ @classmethod def from_value(cls, value: CensusValue) -> 'SearchModifier': From d88a645163ae09fff13c8edd5ea7899d247f7cfd Mon Sep 17 00:00:00 2001 From: "Leonhard S." Date: Mon, 4 Nov 2024 16:42:36 +0100 Subject: [PATCH 3/3] Extend CI Python version coverage --- .github/workflows/ci-testing.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-testing.yaml b/.github/workflows/ci-testing.yaml index 5905c0a..2b4d042 100644 --- a/.github/workflows/ci-testing.yaml +++ b/.github/workflows/ci-testing.yaml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v3