From e999b0604145191c6ec9f7e23a8f04074455f637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tero=20Ykspet=C3=A4j=C3=A4?= Date: Thu, 5 Oct 2023 17:00:16 +0300 Subject: [PATCH] Use Optional for backwards compatibility --- valohai_yaml/objs/workload_resources.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/valohai_yaml/objs/workload_resources.py b/valohai_yaml/objs/workload_resources.py index 6064abd..249ee30 100644 --- a/valohai_yaml/objs/workload_resources.py +++ b/valohai_yaml/objs/workload_resources.py @@ -9,8 +9,8 @@ class ResourceCPU(Item): def __init__( self, - max_value: int | None, - min_value: int | None, + max_value: Optional[int], + min_value: Optional[int], ) -> None: self.max = max_value self.min = min_value @@ -25,8 +25,8 @@ class ResourceMemory(Item): def __init__( self, - max_value: int | None, - min_value: int | None, + max_value: Optional[int], + min_value: Optional[int], ) -> None: self.max = max_value self.min = min_value @@ -67,9 +67,9 @@ class WorkloadResources(Item): def __init__( self, *, - cpu: ResourceCPU | None, - memory: ResourceMemory | None, - devices: ResourceDevices | None, + cpu: Optional[ResourceCPU], + memory: Optional[ResourceMemory], + devices: Optional[ResourceDevices], ) -> None: self.cpu = cpu self.memory = memory @@ -86,19 +86,22 @@ def parse(cls, data: SerializedDict) -> "WorkloadResources": return super().parse(data_with_resources) @classmethod - def _parse_cpu(cls, cpu_data: dict | None) -> Optional["ResourceCPU"]: + def _parse_cpu(cls, cpu_data: Optional[dict]) -> Optional["ResourceCPU"]: if not cpu_data: return None return ResourceCPU(cpu_data.get("max"), cpu_data.get("min")) @classmethod - def _parse_memory(cls, memory_data: dict | None) -> Optional["ResourceMemory"]: + def _parse_memory(cls, memory_data: Optional[dict]) -> Optional["ResourceMemory"]: if not memory_data: return None return ResourceMemory(memory_data.get("max"), memory_data.get("min")) @classmethod - def _parse_devices(cls, devices_data: dict | None) -> Optional["ResourceDevices"]: + def _parse_devices( + cls, + devices_data: Optional[dict], + ) -> Optional["ResourceDevices"]: if not devices_data: return None return ResourceDevices(devices_data)