22 Sep
2020
22 Sep
'20
4:57 p.m.
On 9/22/20 12:11 AM, Serhiy Storchaka wrote:
The only exception is StrEnum -- overriding __str__ of str subclass may be not safe. Some code will call str() implicitly, other will read the string content of the object directly, and they will be different.
Following up on that: >>> import enum >>> >>> class TestStr(enum.StrEnum): ... One = '1' ... Two = '2' ... Three = '3' ... >>> isinstance(TestStr.One, str) True >>> str(TestStr.One) 'TestStr.One' >>> TestStr.One == '1' True I agree, str.__str__ needs to be used in this case. Thanks, Serhiy! -- ~Ethan~