[New-bugs-announce] [issue39587] Mixin repr overrides Enum repr in some cases

Ryan McCampbell report at bugs.python.org
Sat Feb 8 16:01:31 EST 2020


New submission from Ryan McCampbell <rmccampbell7 at gmail.com>:

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
0x1

It uses HexInt's repr instead of Enum's. Looking at the enum.py 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.

----------
components: Library (Lib)
messages: 361635
nosy: rmccampbell7
priority: normal
severity: normal
status: open
title: Mixin repr overrides Enum repr in some cases
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39587>
_______________________________________


More information about the New-bugs-announce mailing list