diff --git a/packages/python/pyproject.toml b/packages/python/pyproject.toml index 254c24b6f..437dde4b0 100644 --- a/packages/python/pyproject.toml +++ b/packages/python/pyproject.toml @@ -45,6 +45,7 @@ tests = [ dev = [ 'mypy', 'ruff', + 'types-protobuf', ] [tool.pytest.ini_options] diff --git a/packages/python/src/armonik/client/events.py b/packages/python/src/armonik/client/events.py index 19c46ede9..e0639fda4 100644 --- a/packages/python/src/armonik/client/events.py +++ b/packages/python/src/armonik/client/events.py @@ -1,4 +1,4 @@ -from typing import Callable, cast, List +from typing import Callable, cast, Iterable, List, Optional from grpc import Channel @@ -42,10 +42,10 @@ def __init__(self, grpc_channel: Channel): def get_events( self, session_id: str, - event_types: List[EventTypes], + event_types: Iterable[EventTypes], # TODO: make EventTypes an enum when Python 3.8 support will be not supported event_handlers: List[Callable[[str, EventTypes, Event], bool]], - task_filter: Filter | None = None, - result_filter: Filter | None = None, + task_filter: Optional[Filter] = None, + result_filter: Optional[Filter] = None, ) -> None: """Get events that represents updates of result and tasks data. @@ -62,13 +62,9 @@ def get_events( """ request = EventSubscriptionRequest(session_id=session_id, returned_events=event_types) if task_filter: - request.tasks_filters = ( - cast(rawTaskFilters, task_filter.to_disjunction().to_message()), - ) + request.tasks_filters = cast(rawTaskFilters, task_filter.to_disjunction().to_message()) if result_filter: - request.results_filters = ( - cast(rawResultFilters, result_filter.to_disjunction().to_message()), - ) + request.results_filters = cast(rawResultFilters, result_filter.to_disjunction().to_message()) streaming_call = self._client.GetEvents(request) for message in streaming_call: diff --git a/packages/python/src/armonik/client/partitions.py b/packages/python/src/armonik/client/partitions.py index 222a92c51..a80d65eb5 100644 --- a/packages/python/src/armonik/client/partitions.py +++ b/packages/python/src/armonik/client/partitions.py @@ -1,4 +1,4 @@ -from typing import List, Tuple, cast +from typing import List, Tuple, cast, Optional from grpc import Channel @@ -49,7 +49,7 @@ def __init__(self, grpc_channel: Channel): def list_partitions( self, - partition_filter: Filter | None = None, + partition_filter: Optional[Filter] = None, page: int = 0, page_size: int = 1000, sort_field: Filter = PartitionFieldFilter.PRIORITY, diff --git a/packages/python/src/armonik/client/results.py b/packages/python/src/armonik/client/results.py index f462ad385..a2da2526d 100644 --- a/packages/python/src/armonik/client/results.py +++ b/packages/python/src/armonik/client/results.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Tuple, cast +from typing import Dict, List, Tuple, cast, Optional, Union from deprecation import deprecated from grpc import Channel @@ -92,7 +92,7 @@ def get_results_ids(self, session_id: str, names: List[str]) -> Dict[str, str]: def list_results( self, - result_filter: Filter | None = None, + result_filter: Optional[Filter] = None, page: int = 0, page_size: int = 1000, sort_field: Filter = ResultFieldFilter.STATUS, @@ -214,7 +214,7 @@ def create_results( return results def upload_result_data( - self, result_id: str, session_id: str, result_data: bytes | bytearray + self, result_id: str, session_id: str, result_data: Union[bytes, bytearray] ) -> None: """Upload data for an empty result already created. diff --git a/packages/python/src/armonik/client/sessions.py b/packages/python/src/armonik/client/sessions.py index 748f60f3e..2fa6b3da9 100644 --- a/packages/python/src/armonik/client/sessions.py +++ b/packages/python/src/armonik/client/sessions.py @@ -127,7 +127,7 @@ def get_session(self, session_id: str): def list_sessions( self, - session_filter: Filter | None = None, + session_filter: Optional[Filter] = None, page: int = 0, page_size: int = 1000, sort_field: Filter = SessionFieldFilter.STATUS, diff --git a/packages/python/src/armonik/client/tasks.py b/packages/python/src/armonik/client/tasks.py index ef69ccae2..e945d8f38 100644 --- a/packages/python/src/armonik/client/tasks.py +++ b/packages/python/src/armonik/client/tasks.py @@ -289,7 +289,7 @@ def get_task(self, task_id: str) -> Task: def list_tasks( self, - task_filter: Filter | None = None, + task_filter: Optional[Filter] = None, with_errors: bool = False, page: int = 0, page_size: int = 1000, @@ -367,7 +367,7 @@ def get_result_ids( tasks_result_ids[t.task_id] = list(t.result_ids) return tasks_result_ids - def count_tasks_by_status(self, task_filter: Filter | None = None) -> Dict[TaskStatus, int]: + def count_tasks_by_status(self, task_filter: Optional[Filter] = None) -> Dict[TaskStatus, int]: """Get number of tasks by status. Args: @@ -393,7 +393,7 @@ def submit_tasks( self, session_id: str, tasks: List[TaskDefinition], - default_task_options: Optional[TaskOptions | None] = None, + default_task_options: Optional[TaskOptions] = None, chunk_size: Optional[int] = 100, ) -> List[Task]: """Submit tasks to ArmoniK. diff --git a/packages/python/src/armonik/common/events.py b/packages/python/src/armonik/common/events.py index f5f66c6a4..b8d0d07b3 100644 --- a/packages/python/src/armonik/common/events.py +++ b/packages/python/src/armonik/common/events.py @@ -1,4 +1,3 @@ -from abc import ABC from typing import List from dataclasses import dataclass @@ -6,7 +5,7 @@ from .enumwrapper import TaskStatus, ResultStatus -class Event(ABC): +class Event: @classmethod def from_raw_event(cls, raw_event): values = {} diff --git a/packages/python/src/armonik/common/helpers.py b/packages/python/src/armonik/common/helpers.py index 81cb6f943..c7abc9d80 100644 --- a/packages/python/src/armonik/common/helpers.py +++ b/packages/python/src/armonik/common/helpers.py @@ -52,7 +52,7 @@ def get_task_filter( return task_filter -def datetime_to_timestamp(time_stamp: datetime | None) -> timestamp.Timestamp: +def datetime_to_timestamp(time_stamp: Optional[datetime]) -> timestamp.Timestamp: """Helper function to convert a Python Datetime to a gRPC Timestamp Args: @@ -68,7 +68,7 @@ def datetime_to_timestamp(time_stamp: datetime | None) -> timestamp.Timestamp: return t -def timestamp_to_datetime(time_stamp: timestamp.Timestamp) -> datetime | None: +def timestamp_to_datetime(time_stamp: timestamp.Timestamp) -> Optional[datetime]: """Helper function to convert a gRPC Timestamp to a Python Datetime Note that datetime has microseconds accuracy instead of nanosecond accuracy for gRPC Timestamp Therefore, the conversion may not be lossless. diff --git a/packages/python/src/armonik/worker/seqlogger.py b/packages/python/src/armonik/worker/seqlogger.py index b08a13d54..11685d4dd 100644 --- a/packages/python/src/armonik/worker/seqlogger.py +++ b/packages/python/src/armonik/worker/seqlogger.py @@ -145,7 +145,7 @@ def log( elif isinstance(exc_info, BaseException): exc_info = (type(exc_info), exc_info, exc_info.__traceback__) payload["@x"] = "\n".join(traceback.format_exception(*exc_info)) - for k, v in kwargs: + for k, v in kwargs.items(): if k.startswith("@"): k = "@" + k payload[k] = str(v) diff --git a/packages/python/src/armonik/worker/taskhandler.py b/packages/python/src/armonik/worker/taskhandler.py index fe8fa6ec5..508150670 100644 --- a/packages/python/src/armonik/worker/taskhandler.py +++ b/packages/python/src/armonik/worker/taskhandler.py @@ -1,7 +1,7 @@ from __future__ import annotations import os from deprecation import deprecated -from typing import Optional, Dict, List, Tuple +from typing import Optional, Dict, List, Tuple, Union from ..common import TaskOptions, TaskDefinition, Task, Result from ..protogen.common.agent_common_pb2 import ( @@ -144,7 +144,7 @@ def submit_tasks( self._client.SubmitTasks(request) - def send_results(self, results_data: Dict[str, bytes | bytearray]) -> None: + def send_results(self, results_data: Dict[str, Union[bytes, bytearray]]) -> None: """Send results. Args: