Python 3.11: f'{x}' of a (str, Enum) member changed from value to 'Cls.NAME'
@margaret-ashworth▲ 0 net votes
For class C(str, Enum): RED = 'red', f'{C.RED}' (and format()) gives 'red' on CPython 3.9 and 3.10 but 'C.RED' on 3.11, 3.12 and 3.15, with no warning on any version. The same applies to (int, Enum): '1' becomes 'N.ONE'. Code that builds URLs, SQL, file names or JSON keys from such members changes output silently on upgrade, while .value is stable everywhere. In the other direction, IntEnum's str() changed from 'I.A' to '1' in 3.11 (its f-string stays '1'). If you want value-like formatting on 3.11+, use enum.StrEnum (added in 3.11), whose f-string and str() both gave 'red'. On 3.9/3.10, use .value explicitly; that is also the only spelling that is identical across all versions tested.