Skip to content

Commit 1d63f20

Browse files
rename interface classes and split register_sliding_window_callback
1 parent 81a79b8 commit 1d63f20

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

src/deisa/common/interface.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,58 +26,50 @@
2626
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2727
# POSSIBILITY OF SUCH DAMAGE.
2828
# =============================================================================
29-
from typing import Protocol, Any, Callable, overload, List, Union, Tuple
29+
from typing import Protocol, Any, Callable, List, Union, Tuple
3030

3131
import dask.array as da
3232
import numpy as np
3333
from distributed import Future, Client
3434

3535

36-
class SlidingWindowInterface(Protocol):
37-
Callback_args = Union[str, Tuple[str], Tuple[str, int]] # array_name, (array_name, ...), (array_name, window_size)
38-
39-
class SlidingWindowCallbackInterface(Protocol):
36+
class SupportsSlidingWindow(Protocol):
37+
class Callback(Protocol):
4038
def __call__(self, *window: List[da.Array], timestep: int) -> None: ...
4139

42-
class ExceptionHandlerInterface(Protocol):
40+
class ExceptionHandler(Protocol):
4341
def __call__(self, array_name: str, exception: BaseException) -> None: ...
4442

45-
@overload
46-
def register_sliding_window_callback(self, callback: SlidingWindowCallbackInterface,
47-
array_name: str, *, window_size: int = 1,
48-
exception_handler: ExceptionHandlerInterface) -> None: ...
49-
50-
@overload
51-
def register_sliding_window_callback(self, callback: SlidingWindowCallbackInterface,
52-
*callback_args: Callback_args,
53-
exception_handler: ExceptionHandlerInterface,
54-
when='AND') -> None: ...
43+
def register_sliding_window_callback(self,
44+
callback: Callback,
45+
array_name: str, window_size: int,
46+
exception_handler: ExceptionHandler) -> str: ...
5547

56-
def register_sliding_window_callback(self, callback: SlidingWindowCallbackInterface,
57-
*callback_args: Callback_args,
58-
window_size: int = 1,
59-
exception_handler: ExceptionHandlerInterface,
60-
when: str = 'AND') -> str: ...
48+
def register_sliding_window_callbacks(self,
49+
callback: Callback,
50+
*callback_args: Union[str, Tuple[str], Tuple[str, int]],
51+
exception_handler: ExceptionHandler,
52+
when: str = 'AND') -> str: ...
6153

62-
def unregister_sliding_window_callback(self, *array_names: Callback_args) -> None: ...
54+
def unregister_sliding_window_callback(self, *array_names: Union[str, Tuple[str]]) -> None: ...
6355

6456

65-
class GetArrayInterface(Protocol):
57+
class SupportsGetArray(Protocol):
6658
def get_array(self, array_name: str, timeout=None) -> tuple[da.Array, int]: ...
6759

6860

69-
class DeisaInterface(SlidingWindowInterface, GetArrayInterface, Protocol):
61+
class IDeisa(SupportsSlidingWindow, SupportsGetArray, Protocol):
7062

7163
def __init__(self, get_connection_info: Callable[[], Client], *args, **kwargs): ...
7264

73-
def set(self, name: str, data: Union[Future, object], chunked=False) -> None: ...
65+
def set(self, name: str, data: Union[Future, object], chunked: bool) -> None: ...
7466

7567
def delete(self, key: str) -> None: ...
7668

7769
def close(self) -> None: ...
7870

7971

80-
class BridgeInterface(Protocol):
72+
class IBridge(Protocol):
8173
def __init__(self, id: int, arrays_metadata: dict[str, dict], system_metadata: dict[str, Any], *args, **kwargs): ...
8274

8375
def send(self, array_name: str, data: np.ndarray, timestep: int, chunked: bool) -> None: ...

0 commit comments

Comments
 (0)