-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum: mixin classes don't mix well with already mixed Enums #73763
Comments
Consider: class AllEnum(Enum):
@classattr
def ALL(cls):
members = list(cls)
all_value = None
if members:
all_value = members[0]
for member in members[1:]:
all_value |= member
cls.ALL = all_value
return all_value
class Color(AllEnum, Flag):
RED = auto()
BLUE = auto()
GREEN = auto()
class IntColor(AllEnum, IntFlag):
RED = auto()
BLUE = auto()
GREEN = auto() The Color class works fine, but the IntColor fails. This is due to the way the base data type and __new__ method is discovered. If we switch the order of the bases class IntColor(IntFlag, AllEnum) it works, but having to put the mixin class last is both bizarre and unworkable when the mixin should be overriding behavior. |
To get the above code snippet to fail properly:
|
While only IntColor fails with an error, Color also fails as it is not a Flag type Enum: >>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>] It should have values of 1, 2, 4. |
Possibilities:
The last one needs to happen, and some form of the next-to-last one (hopefully allowing for more than one non-Enum mixin). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: