[Python-ideas] IntFlags
Alexander Heger
python at 2sn.net
Wed Mar 4 19:37:38 CET 2015
> That should be a sanity error, but since an IntEnum devolves to an
> int, it just produces a nonsensical integer. It definitely shouldn't
> become an IntFlags. There are two distinctly different use-cases here:
>
> class Color(IntEnum):
> black = 0
> red = 1
> green = 2
> orange = 3
> blue = 4
> magenta = 5
> cyan = 6
> white = 7
>
> class FileMode(IntFlags):
> owner_read = 0o400
> owner_write= 0o200
> owner_exec = 0o100
> group_read = 0o040
> group_write= 0o020
> group_exec = 0o010
> other_read = 0o004
> other_write= 0o002
> other_exec = 0o001
>
> 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.
I don't see your point. With colours it would be exactly the same:
red | blue == magenta
and for your example:
cyan | blue = cyan
As with the later discussion on file flags, cyan is just a combination
flag for green and blue.
-Alexander
More information about the Python-ideas
mailing list