Skip to content

Commit

Permalink
WIP: making suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Jun 5, 2024
1 parent 228656c commit 7a8fa6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ophyd_async/core/signal_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import abstractmethod
from typing import (
TYPE_CHECKING,
ClassVar,
Dict,
FrozenSet,
Generic,
Expand Down Expand Up @@ -66,7 +67,7 @@ class _RuntimeEnumMeta(type):

def __str__(cls):
if hasattr(cls, "_choices"):
return f"RuntimeEnum{list(cls._choices.keys())}"
return f"RuntimeEnum{list(cls.choices)}"
return "RuntimeEnum"

@property
Expand Down Expand Up @@ -94,11 +95,13 @@ def __getitem__(cls, choices):

# Create a new enum subclass
class _RuntimeEnum(cls):
_choices = {choice: choice for choice in choices}
choices = choices_frozenset

_RuntimeEnumMeta.__enum_classes_created[choices_frozenset] = _RuntimeEnum
return _RuntimeEnum

class RuntimeEnum(metaclass=_RuntimeEnumMeta):
choices: ClassVar[FrozenSet[str]]

def __init__(self):
raise RuntimeError("RuntimeEnum cannot be instantiated")
2 changes: 1 addition & 1 deletion src/ophyd_async/epics/_backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_supported_values(
return {x: x or "_" for x in pv_choices}

if issubclass(datatype, RuntimeEnum):
pv_choices = datatype.choices
assert frozenset(pv_choices).issubset(datatype.choices)
elif not issubclass(datatype, str):
raise TypeError(f"{pv} is type Enum but doesn't inherit from String")
elif issubclass(datatype, Enum):
Expand Down

0 comments on commit 7a8fa6a

Please sign in to comment.