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 -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/A4ZHD3J47IKNNMQEJFIJQPMFBQH6HAZM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to