You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
fromenumimportEnumclassBase:
name='base'classChild(Base):
name='child'classBaseEnum(Base, Enum):
FOO=Child()
print(BaseEnum.FOO.name) # outputs 'base' when 'child' is expectedprint(BaseEnum.FOO.value.name) # outputs 'child' as expected
CPython versions tested on:
3.12
Operating systems tested on:
Linux, Windows
The text was updated successfully, but these errors were encountered:
Right. It isn't clear why the Activations class in the SO question needs to be an Enum at all in the first place, and I can't think of a good real-world use case myself. I simply concur with the OP of the SO question that the behavior is somewhat unexpected/counter-intuitive. That's all.
Just left a comment in the SO question requesting clarification.
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:
CPython versions tested on:
3.12
Operating systems tested on:
Linux, Windows
The text was updated successfully, but these errors were encountered: