We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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?
to your account
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
assignee = 'https://github.com/ethanfurman'
closed_at = <Date 2021-01-14.01:26:05.907>
created_at = <Date 2017-12-05.03:44:12.300>
labels = ['type-feature', 'library', '3.10']
title = 'add __iter__ to enum.Flag members'
updated_at = <Date 2021-01-14.01:26:05.905>
user = 'https://bugs.python.org/GuyGangemi'
activity = <Date 2021-01-14.01:26:05.905>
actor = 'ethan.furman'
assignee = 'ethan.furman'
closed = True
closed_date = <Date 2021-01-14.01:26:05.907>
closer = 'ethan.furman'
components = ['Library (Lib)']
creation = <Date 2017-12-05.03:44:12.300>
creator = 'Guy Gangemi'
dependencies = 
files = 
hgrepos = 
issue_num = 32218
keywords = ['patch']
message_count = 5.0
messages = ['307629', '311204', '377152', '381368', '385060']
nosy_count = 7.0
nosy_names = ['barry', 'rhettinger', 'eli.bendersky', 'ethan.furman', 'hongweipeng', 'cryvate', 'Guy Gangemi']
pr_nums = ['22221', '23368']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue32218'
versions = ['Python 3.10']
The text was updated successfully, but these errors were encountered:
I'm proposing to extend enum.Flag member functionality so it is iterable in a manner similar to enum.Flag subclasses.
from enum import Flag, auto
for memeber in self._member_map_.values():
if member in self:
RED = auto()
GREEN = auto()
BLUE = auto()
YELLOW = RED | GREEN
cyan = Colour.GREEN | Colour.Blue
print(*Colour) # Colour.RED Colour.GREEN Colour.BLUE Colour.YELLOW
# Without the enhancement, 'not iterable' is thrown for these
print(*cyan) # Colour.GREEN Colour.BLUE
print(*Colour.YELLOW) # Colour.RED Colour.GREEN Colour.YELLOW
print(*~Colour.RED) # Colour.GREEN Colour.BLUE
Sorry, something went wrong.
This functionality is now in the third-party aenum* library.
Are there any strong use-cases for this behavior such that it should be in the stdlib?
Problem: What to do when the Flag has compound members?
BLACK = 0
RED = 1
GREEN = 2
BLUE = 4
PURPLE = RED|BLUE
WHITE = RED|GREEN|BLUE
I think the answer is: only return the single members. So
[Color.BLUE, Color.GREEN, Color.RED]
What does aenum do and has there been any feedback on it?
To me I would see what you suggest as surprising but I don't use enums often (I should use them more!) so take that with a grain of salt, and also surprising != wrong/not good.
Flag has been redesigned such that any flag comprised of a single bit is canonical; flags comprised of multiple bits are considered aliases. During iteration only canonical flags are returned.
No branches or pull requests