[Python-ideas] IntFlags

Chris Angelico rosuav at gmail.com
Wed Mar 4 21:58:38 CET 2015


On Thu, Mar 5, 2015 at 6:48 AM,  <random832 at fastmail.us> wrote:
> On Tue, Mar 3, 2015, at 17:16, Chris Angelico wrote:
>> class Color(IntEnum):
>>     black = 0
>>     red = 1
>>     green = 2
>>     orange = 3
>>     blue = 4
>>     magenta = 5
>>     cyan = 6
>>     white = 7
>>
>> With colors, it makes no sense to combine them in any way (addition,
>> bitwise or, etc). You can't put blue and cyan together and expect to
>> get something usable.
>
> Except for the part where green|blue==cyan... and if only you'd said
> yellow instead of orange it'd hold across the board. I assume you took
> these values from ANSI colors.

Those are indeed the ANSI colors, but even though you might think that
you can combine them, they don't really combine usefully in all cases.
But sure. If you're bothered by the fact that blue+green == cyan, use
a different example. Turn 'em into animals, cars, CPU models, whatever
you like; the point of an IntEnum is usually just that the values are
unique, _not_ that they can be combined in any meaningful way.

ChrisA


More information about the Python-ideas mailing list