Skip to content

AttributeError in 3.11 on repr() of enum member if the enum has a non-Enum EnumType parent #102558

Closed
@vashek

Description

@vashek

Bug report

In CPython 3.11.0 - 3.11.2 (but not 3.10.10), I get a weird AttributeError when repr() is called on an Enum member of a class that was defined using multiple inheritance. Minimal code to reproduce:

from enum import Enum, EnumMeta

class _EnumSuperClass(metaclass=EnumMeta):
    pass

class E(_EnumSuperClass, Enum):
    A=1

print(repr(E.A))

With Python up to 3.10, the output is:

<E.A: 1>

With Python 3.11, the output is:

Traceback (most recent call last):
  File "C:\devel\tmp\api\e.py", line 9, in <module>
    print(repr(E.A))
          ^^^^^^^^^
  File "C:\Program Files\Python311\Lib\enum.py", line 1169, in __repr__
    return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
                                                                  ^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\enum.py", line 1168, in __repr__
    v_repr = self.__class__._value_repr_ or repr
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'int' has no attribute '_value_repr_'

Your environment

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
(But reproduced also on 3.11.2)

Linked PRs

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions