This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jason.curtis
Recipients jason.curtis
Date 2019-07-01.23:24:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562023451.58.0.339794314518.issue37479@roundup.psfhosted.org>
In-reply-to
Content
Combining int and Enum, as with enum.IntEnum results in a class where __str__ cannot be effectively overridden. For example:


from enum import IntEnum

class myIntEnum(IntEnum):
    x = 1
    
    def __str__(self):
        return 'aaaaAAAa'
    
f'{myIntEnum.x}, {str(myIntEnum.x)}'


Expected output:
'aaaaAAAa, aaaaAAAa'

Actual output:
'1, aaaaAAAa'

Overriding __str__ in this way works as expected if the inherited classes are int or Enum individually. However, it does not work when inheriting (int, Enum) or when inheriting (intEnum).

Presumably this is a side effect of Enum's mixin behavior documented at https://docs.python.org/3/library/enum.html#others and it is possibly related to https://bugs.python.org/issue18264 .
History
Date User Action Args
2019-07-01 23:24:11jason.curtissetrecipients: + jason.curtis
2019-07-01 23:24:11jason.curtissetmessageid: <1562023451.58.0.339794314518.issue37479@roundup.psfhosted.org>
2019-07-01 23:24:11jason.curtislinkissue37479 messages
2019-07-01 23:24:11jason.curtiscreate