From a90dcff2bb3fd0bdd8e928b57569a5c27bbc10d7 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Wed, 22 Jan 2025 10:59:02 +0100 Subject: [PATCH] Using typing-extensions for 3.9 support of @override --- pyproject.toml | 1 + src/plumpy/base/state_machine.py | 2 ++ src/plumpy/persistence.py | 2 ++ src/plumpy/process_states.py | 2 +- src/plumpy/processes.py | 10 ++++++---- uv.lock | 2 ++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ba563ac8..574173d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ dependencies = [ 'kiwipy[rmq]~=0.8.5', 'nest_asyncio~=1.5,>=1.5.1', 'pyyaml~=6.0', + 'typing-extensions~=4.12' ] [project.urls] diff --git a/src/plumpy/base/state_machine.py b/src/plumpy/base/state_machine.py index 814c1491..a12981a0 100644 --- a/src/plumpy/base/state_machine.py +++ b/src/plumpy/base/state_machine.py @@ -275,6 +275,8 @@ def state(self) -> State | None: def state_label(self) -> Any: if self._state is None: return None + # XXX: should not use `.value` to access the printable output from LABEL + # LABEL as the ClassVar should have __str__ return self._state.LABEL def add_state_event_callback(self, hook: Hashable, callback: EVENT_CALLBACK_TYPE) -> None: diff --git a/src/plumpy/persistence.py b/src/plumpy/persistence.py index 31bbc67c..b2da7eef 100644 --- a/src/plumpy/persistence.py +++ b/src/plumpy/persistence.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import annotations + import abc import asyncio import collections diff --git a/src/plumpy/process_states.py b/src/plumpy/process_states.py index 704da6eb..c245d72a 100644 --- a/src/plumpy/process_states.py +++ b/src/plumpy/process_states.py @@ -17,10 +17,10 @@ Union, cast, final, - override, ) import yaml +from typing_extensions import override from yaml.loader import Loader from plumpy.message import MessageBuilder, MessageType diff --git a/src/plumpy/processes.py b/src/plumpy/processes.py index 2cf20a2a..95f73719 100644 --- a/src/plumpy/processes.py +++ b/src/plumpy/processes.py @@ -285,7 +285,7 @@ def recreate_from( if 'loop' in load_context: proc._loop = load_context.loop else: - _LOGGER.warning(f'cannot find `loop` store in load_context, use default event loop') + _LOGGER.warning('cannot find `loop` store in load_context, use default event loop') proc._loop = asyncio.get_event_loop() proc._state = proc.recreate_state(saved_state['_state']) @@ -293,12 +293,12 @@ def recreate_from( if 'coordinator' in load_context: proc._coordinator = load_context.coordinator else: - _LOGGER.warning(f'cannot find `coordinator` store in load_context') + _LOGGER.warning('cannot find `coordinator` store in load_context') if 'logger' in load_context: proc._logger = load_context.logger else: - _LOGGER.warning(f'cannot find `logger` store in load_context') + _LOGGER.warning('cannot find `logger` store in load_context') # Need to call this here as things downstream may rely on us having the runtime variable above persistence.load_auto_persist_params(proc, saved_state, load_context) @@ -760,7 +760,9 @@ def on_entered(self, from_state: Optional[state_machine.State]) -> None: try: self._coordinator.broadcast_send(body=None, sender=self.pid, subject=subject) except exceptions.CoordinatorCommunicationError: - message = f'Process<{self.pid}>: cannot broadcast state change from {from_label} to {self.state.value}' + message = ( + f'Process<{self.pid}>: cannot broadcast state change from {from_label} to {self.state_label.value}' + ) self.logger.warning(message) self.logger.debug(message, exc_info=True) except Exception: diff --git a/uv.lock b/uv.lock index 2af8adbd..d8fc89f5 100644 --- a/uv.lock +++ b/uv.lock @@ -1862,6 +1862,7 @@ dependencies = [ { name = "kiwipy", extra = ["rmq"] }, { name = "nest-asyncio" }, { name = "pyyaml" }, + { name = "typing-extensions" }, ] [package.optional-dependencies] @@ -1913,6 +1914,7 @@ requires-dist = [ { name = "sphinx", marker = "extra == 'docs'", specifier = "~=3.2.0" }, { name = "sphinx-book-theme", marker = "extra == 'docs'", specifier = "~=0.0.39" }, { name = "types-pyyaml", marker = "extra == 'pre-commit'" }, + { name = "typing-extensions", specifier = "~=4.12" }, ] [[package]]