From 6b9486431afb9e47ed3b65112b5736ab634f2f43 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 20 Dec 2024 09:52:38 -0800 Subject: [PATCH] Use StrEnum instead of dual inheritance Rather than inheriting from `str, Enum`, use the `StrEnum` parent class, which does the same thing more thoroughly. --- client/src/rubin/nublado/client/models/_image.py | 4 ++-- controller/src/controller/models/domain/kubernetes.py | 6 +++--- controller/src/controller/models/v1/lab.py | 4 ++-- spawner/src/rubin/nublado/spawner/_models.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/src/rubin/nublado/client/models/_image.py b/client/src/rubin/nublado/client/models/_image.py index d242bc953..7b5bac690 100644 --- a/client/src/rubin/nublado/client/models/_image.py +++ b/client/src/rubin/nublado/client/models/_image.py @@ -3,13 +3,13 @@ from __future__ import annotations from abc import ABCMeta, abstractmethod -from enum import Enum +from enum import Enum, StrEnum from typing import Literal, override from pydantic import BaseModel, Field -class NubladoImageClass(str, Enum): +class NubladoImageClass(StrEnum): """Possible ways of selecting an image.""" __slots__ = () diff --git a/controller/src/controller/models/domain/kubernetes.py b/controller/src/controller/models/domain/kubernetes.py index 1af9e1dee..ba6affaae 100644 --- a/controller/src/controller/models/domain/kubernetes.py +++ b/controller/src/controller/models/domain/kubernetes.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass -from enum import Enum +from enum import Enum, StrEnum from typing import Annotated, Any, Protocol, Self, override from kubernetes_asyncio.client import ( @@ -599,7 +599,7 @@ def to_kubernetes(self) -> V1Affinity: ) -class PodPhase(str, Enum): +class PodPhase(StrEnum): """One of the valid phases reported in the status section of a Pod.""" PENDING = "Pending" @@ -759,7 +759,7 @@ def to_kubernetes(self) -> V1Toleration: ) -class VolumeAccessMode(str, Enum): +class VolumeAccessMode(StrEnum): """Access mode for a persistent volume. The access modes ``ReadWriteOnce`` and ``ReadWriteOncePod`` are valid diff --git a/controller/src/controller/models/v1/lab.py b/controller/src/controller/models/v1/lab.py index 30179083b..13dd3ee2c 100644 --- a/controller/src/controller/models/v1/lab.py +++ b/controller/src/controller/models/v1/lab.py @@ -2,7 +2,7 @@ from __future__ import annotations -from enum import Enum +from enum import Enum, StrEnum from typing import Annotated, Any, Self from kubernetes_asyncio.client import V1ResourceRequirements @@ -35,7 +35,7 @@ ] -class LabSize(str, Enum): +class LabSize(StrEnum): """Allowable names for pod sizes. Taken from `d20 creature sizes`_. diff --git a/spawner/src/rubin/nublado/spawner/_models.py b/spawner/src/rubin/nublado/spawner/_models.py index da5dbc630..8c9cd1d5a 100644 --- a/spawner/src/rubin/nublado/spawner/_models.py +++ b/spawner/src/rubin/nublado/spawner/_models.py @@ -3,12 +3,12 @@ from __future__ import annotations from dataclasses import dataclass -from enum import Enum +from enum import StrEnum from httpx_sse import ServerSentEvent -class LabStatus(str, Enum): +class LabStatus(StrEnum): """Possible status conditions of a user's pod per the lab controller. This is not directly equivalent to pod phases. It is instead intended to