[Python-ideas] PEP XXX - Competitor with PEP 435: Adding an enum type to the Python standard library
abarnert at yahoo.com
Wed Mar 13 07:08:22 CET 2013
On Mar 12, 2013, at 19:04, Random832 <random832 at fastmail.us> wrote:
> On 03/12/2013 09:43 PM, Andrew Barnert wrote:
>> You also need negated values, or there's no way to write "background &= ~Color.RED". So, "~Color.RED" has to be something.
> No, you don't. I started saying the same thing (then got sidetracked into trying to define it as a general operation on sets, then abandoned the idea as silly) in my last, but.... why not just background -= Color.RED? Just like sets.
Which means, as I said in another message, that Day.FRIDAY - Day.WEDNESDAY is not 2, but Day.FRIDAY. Which I'm pretty sure most people would find surprising.
Unless you want bitmask and ordered int enums to be different types, I don't see a good way around this. A type that acts like a set and also like a number has conflicting intuitive meanings for most of its operators.
The only reason you don't notice this for the obvious ones | and & is that those two set operations mean the same thing as the int operations (when thinking of an int as a set of bits); that's not true for any operators other than the bitwise ones.
> It's different from C, but that's not necessarily a bad thing.
> Python-ideas mailing list
> Python-ideas at python.org
More information about the Python-ideas