[Python-Dev] Re: Enum and the Standard Library

2020年9月22日 07:02:30 -0700

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~
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/A4ZHD3J47IKNNMQEJFIJQPMFBQH6HAZM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to