Skip to content

Commit

Permalink
Use Optional for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
teroyks committed Oct 5, 2023
1 parent ce197ce commit e999b06
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions valohai_yaml/objs/workload_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e999b06

Please sign in to comment.