99class StrEnumWithXml (StrEnum ):
1010 """String enum with xml value."""
1111
12- xml_value : str
12+ xml_value : str | None
1313
14- def __new__ (cls , value : str , xml_value : str = "" ) -> Self :
14+ def __new__ (cls , value : str , xml_value : str | None = None ) -> Self :
1515 """Create new StrEnumWithXml."""
1616 obj = str .__new__ (cls , value )
1717 obj ._value_ = value
1818 obj .xml_value = xml_value
1919 return obj
2020
2121 @classmethod
22- def from_xml (cls , value : str ) -> Self :
22+ def from_xml (cls , value : str | None ) -> Self :
2323 """Convert from xml value."""
24- for member in cls :
25- if member .xml_value == value :
26- return member
24+ if value :
25+ for member in cls :
26+ if member .xml_value == value :
27+ return member
2728
2829 msg = f"{ value } is not a valid { cls .__name__ } "
2930 raise ValueError (msg )
@@ -32,21 +33,22 @@ def from_xml(cls, value: str) -> Self:
3233class IntEnumWithXml (IntEnum ):
3334 """Int enum with xml value."""
3435
35- xml_value : str
36+ xml_value : str | None
3637
37- def __new__ (cls , value : int , xml_value : str = "" ) -> Self :
38+ def __new__ (cls , value : int , xml_value : str | None = None ) -> Self :
3839 """Create new StrEnumWithXml."""
3940 obj = int .__new__ (cls , value )
4041 obj ._value_ = value
4142 obj .xml_value = xml_value
4243 return obj
4344
4445 @classmethod
45- def from_xml (cls , value : str ) -> Self :
46+ def from_xml (cls , value : str | None ) -> Self :
4647 """Convert from xml value."""
47- for member in cls :
48- if member .xml_value == value :
49- return member
48+ if value :
49+ for member in cls :
50+ if member .xml_value == value :
51+ return member
5052
5153 msg = f"{ value } is not a valid { cls .__name__ } "
5254 raise ValueError (msg )
0 commit comments