New submission from Guy Gangemi <[email protected]>:
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
class FlagIter(Flag):
def __iter__(self):
for memeber in self._member_map_.values():
if member in self:
yield member
class Colour(FlagIter):
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
----------
messages: 307629
nosy: Guy Gangemi
priority: normal
severity: normal
status: open
title: add __iter__ to enum.Flag members
type: enhancement
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32218>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com