From 633782e339b10c4c246fc44a72f2cf2ed663b34f Mon Sep 17 00:00:00 2001 From: Shihab Suliman Date: Fri, 24 Jan 2025 15:30:18 +0000 Subject: [PATCH] Add docstring to subsetenummeta call dunder --- src/ophyd_async/core/_utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ophyd_async/core/_utils.py b/src/ophyd_async/core/_utils.py index b19540e101..d07be32a19 100644 --- a/src/ophyd_async/core/_utils.py +++ b/src/ophyd_async/core/_utils.py @@ -34,6 +34,20 @@ class StrictEnum(str, Enum, metaclass=StrictEnumMeta): class SubsetEnumMeta(StrictEnumMeta): def __call__(self, value, *args, **kwargs): # type: ignore + """ + Returns given value if it is a string and not a member of the enum. + If the value is not a string or is an enum member, default enum behavior + is applied. Type checking will complain if provided arbitrary string. + + Returns: + Union[str, SubsetEnum]: If the value is a string and not a member of the + enum, the string is returned as is. Otherwise, the corresponding enum + member is returned. + + Raises: + ValueError: If the value is not a string and cannot be converted to an enum + member. + """ if isinstance(value, str) and not isinstance(value, self): return value return super().__call__(value, *args, **kwargs)