Title: Mixin repr overrides Enum repr in some cases
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: barry, eli.bendersky, ethan.furman, rmccampbell7, xtreak
Priority: normal Keywords:

Created on 2020-02-08 21:01 by rmccampbell7, last changed 2020-02-10 05:55 by xtreak.

Messages (2)
msg361635 - (view) Author: Ryan McCampbell (rmccampbell7) Date: 2020-02-08 21:01
In Python 3.6 the following works:

class HexInt(int):
    def __repr__(self):
        return hex(self)

class MyEnum(HexInt, enum.Enum):
    A = 1
    B = 2
    C = 3

>>> MyEnum.A
<MyEnum.A: 0x1>

However in Python 3.7/8 it instead prints
>>> MyEnum.A

It uses HexInt's repr instead of Enum's. Looking at the module it seems that this occurs for mixin classes that don't define __new__ due to a change in the _get_mixins_ method. If I define a __new__ method on the HexInt class then the expected behavior occurs.
msg361667 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-02-10 05:55
Bisecting points to issue29577 that introduced this change.
Date User Action Args
2020-02-10 05:55:23xtreaksetnosy: + xtreak
messages: + msg361667
2020-02-09 04:17:18rhettingersetassignee: ethan.furman
2020-02-09 04:15:41xtreaksetnosy: + barry, eli.bendersky, ethan.furman
2020-02-08 21:01:31rmccampbell7create