@@ -192,7 +192,16 @@ def get_field_members(cls) -> Dict:
192192
193193
194194class StructuredEnum (OrigEnum , metaclass = StructuredEnumMeta ):
195- """Structured Enum type, providing extra features such as getting enum members as choices tuple"""
195+ """
196+ Structured Enum type, providing extra features such as getting enum members as choices tuple
197+
198+ NOTE: XEnum(str / int, StructuredEnum) not working in string formatting since python 3.11,
199+ please use StrStructuredEnum / IntStructuredEnum instead of StructuredEnum
200+ refs:
201+ - https://github.com/python/cpython/issues/100458
202+ - https://github.com/TencentBlueKing/bkpaas-python-sdk/issues/190
203+ - https://blog.pecar.me/python-enum
204+ """
196205
197206 @classmethod
198207 def get_django_choices (cls ) -> List [Tuple [Any , str ]]:
@@ -227,3 +236,26 @@ def get_choices(cls) -> List[Tuple[Any, str]]:
227236 """Get Choices for all field members."""
228237 members = cls .get_field_members ()
229238 return [(field .real_value , field .label ) for field in members .values ()]
239+
240+
241+ try :
242+ # python 3.11+ required
243+ from enum import StrEnum , IntEnum
244+ except ImportError :
245+ pass
246+ else :
247+ class StrStructuredEnum (StructuredEnum , StrEnum ):
248+ """
249+ StrStructuredEnum ensures the literals in f-string / str.format() is real_value
250+
251+ Important: Use XEnum(StrStructuredEnum) instead of XEnum(str, StructuredEnum) since python 3.11
252+ """
253+ pass
254+
255+ class IntStructuredEnum (StructuredEnum , IntEnum ):
256+ """
257+ IntStructuredEnum ensures the literals in f-string / str.format() is real_value
258+
259+ Important: Use XEnum(IntStructuredEnum) instead of XEnum(int, StructuredEnum) since python 3.11
260+ """
261+ pass
0 commit comments