Skip to content

Attribute resolution of an Enum member that is an instance of a subclass of the mixin class does not follow MRO #116487

@blhsing

Description

@blhsing

Bug report

Bug description:

As reported in https://stackoverflow.com/questions/78120133/python-enum-of-classes-with-polymorphism .

Since the idea of a mixin class to an Enum is to make the members behave like instances of the mixin class, I think it's reasonable to expect that attribute resolution of a member whose value is an instance of a subclass of the mixin class follows MRO as well. Currently the attribute resolution appears to stick to the base mixin class.

Minimal reproducible example:

from enum import Enum

class Base:
    name = 'base'

class Child(Base):
    name = 'child'

class BaseEnum(Base, Enum):
    FOO = Child()

print(BaseEnum.FOO.name) # outputs 'base' when 'child' is expected
print(BaseEnum.FOO.value.name) # outputs 'child' as expected

CPython versions tested on:

3.12

Operating systems tested on:

Linux, Windows

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions