Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Snoopy1866 committed Sep 11, 2024
1 parent 23d06d1 commit 572ea98
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from enum import Enum
from typing import Type

from .exception import EnumMemberNotExistError


def get_enum_by_name(enum_class: Type[Enum], name: str) -> Enum:
"""根据枚举成员名的字符串表示获取枚举成员。
Parameters
----------
enum_class : Type[T]
枚举类
name : str
枚举名称的字符串表示
Returns
-------
T
枚举成员
"""

if name is None or isinstance(name, enum_class):
return name
else:
try:
return enum_class[name.upper()]
except KeyError:
raise EnumMemberNotExistError(enum_class, name)

0 comments on commit 572ea98

Please sign in to comment.