[Python-ideas] PEP XXX - Competitor with PEP 435: Adding an enum type to the Python standard library

Andrew Barnert abarnert at yahoo.com
Wed Mar 13 02:58:23 CET 2013

> From: Random832 <random832 at fastmail.us>

> Sent: Tuesday, March 12, 2013 6:03 PM
> Subject: Re: [Python-ideas] PEP XXX - Competitor with PEP 435: Adding an enum type to the Python standard library
> 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_.

That means that in order to make a window non-resizable, instead of this:

    window.style &= ~wx.RESIZE_BORDER

you do this:

    window.style -= wx.RESIZE_BORDER

Right? (IIRC, the actual code is probably something like "window.setStyle(window.getStyle() & ~wx.RESIZE_BORDER)", but I think we can ignore that; the issue is the same.)

That solves the problem of how to represent ~wx.RESIZE_BORDER, etc. But it creates a new problem.

Now non-bitmask integral Enum constants don't have integral-type operators, but set-type operators. So "FRIDAY - WEDNESDAY" returns "FRIDAY" (because it's set difference), and "WEDNESDAY < FRIDAY" is false (because it's not a proper subset)?

So I think this means you _do_ need separate types for bitmasked and ordered int values—or, alternatively, for set-able and non-set-able Enums, which I think Alex Stewart was able to eliminate.

> 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,

Well, you need to be able to get the int value of a set, too. What's the point of being able to do mmap.PROT_READ | mmap.PROT_WRITE if I (or the mmap module) can't turn that into a 3?

Also, what happens if you call the constructor on a sequence of more than one instance?

More information about the Python-ideas mailing list