[issue23591] Add Flags and IntFlags
Ethan Furman
report at bugs.python.org
Mon Aug 15 17:24:29 EDT 2016
Ethan Furman added the comment:
The values used in Flags are an implementation detail. The expected, and supported, use is naming the flags:
class Color(Flags):
Red, Green, Blue
even custom names can be set using this method:
>>> class Color(enum.Flags):
... red, green, blue
... black = red & green & blue
...
>>> list(Color)
[<Color.red: 1>, <Color.green: 2>, <Color.blue: 4>, <Color.black: 0>]
>>> class Color(enum.Flags):
... red, green, blue
... purple = red | blue
...
>>> list(Color)
[<Color.red: 1>, <Color.green: 2>, <Color.blue: 4>, <Color.purple: 5>]
>>> Color(5)
<Color.purple: 5>
>>> Color(3)
<Color.red|green: 3>
I'll have to think about ensuring each bit is named -- it's only a (potential) problem if the values are specified manually.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23591>
_______________________________________
More information about the Python-bugs-list
mailing list