StringEnum#
- class composer.utils.StringEnum(value)[source]#
- Base class for Enums containing string values. - This class enforces that all keys are uppercase and all values are lowercase. It also offers the following convenience features: - StringEnum(value)will perform a case-insensitive match on both the keys and value, and is a no-op if given an existing instance of the class.- >>> from composer.utils import StringEnum >>> class MyStringEnum(StringEnum): ... KEY = "value" >>> MyStringEnum("KeY") # case-insensitive match on the key <MyStringEnum.KEY: 'value'> >>> MyStringEnum("VaLuE") # case-insensitive match on the value <MyStringEnum.KEY: 'value'> >>> MyStringEnum(MyStringEnum.KEY) # no-op if given an existing instance <MyStringEnum.KEY: 'value'> 
- Equality checks support case-insensitive comparisons against strings: - >>> from composer.utils import StringEnum >>> class MyStringEnum(StringEnum): ... KEY = "value" >>> MyStringEnum.KEY == "KeY" # case-insensitive match on the key True >>> MyStringEnum.KEY == "VaLuE" # case-insensitive match on the value True >>> MyStringEnum.KEY == "something else" False