This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Guy Gangemi
Recipients Guy Gangemi
Date 2017-12-05.03:44:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512445452.31.0.213398074469.issue32218@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-12-05 03:44:12Guy Gangemisetrecipients: + Guy Gangemi
2017-12-05 03:44:12Guy Gangemisetmessageid: <1512445452.31.0.213398074469.issue32218@psf.upfronthosting.co.za>
2017-12-05 03:44:12Guy Gangemilinkissue32218 messages
2017-12-05 03:44:11Guy Gangemicreate