[Python-ideas] PEP XXX - Competitor with PEP 435: Adding an enum type to the Python standard library
Random832
random832 at fastmail.us
Wed Mar 13 02:03:48 CET 2013
On 03/12/2013 06:17 PM, Alex Stewart wrote:
> effectively multi-enum sets
Speaking of sets... it seems like sets of single enum values would be a
good way to represent "ORed-together enums". But then if you want a
function to accept one, it has to be able to not care if it's only a
single one or not.
So, what if each value of a 'flags' type enum is also able to be treated
as a single-member set of itself? We already have one object that
iterates into a sequence the same class: strings, so there's nothing
wrong with that _conceptually_.
The constructor could turn a sequence of the enum into a proper instance
of it [if needed to get the int value] for passing into functions that
require one, and a function that takes such a set of them could just not
care the difference between Color.red|Color.blue and {Color.red,Color.blue}.
More information about the Python-ideas
mailing list