[issue23591] enum: Add Flags and IntFlags

Ethan Furman report at bugs.python.org
Tue Sep 13 17:32:26 EDT 2016


Ethan Furman added the comment:

Vedran:

1) Thank you for the bug report, it's appreciated.

2) I would appreciate it even more if you just kept it to a bug report
   without the, for lack of a better word, drama.

-----------------------------------------------

>    >>> import enum
>    >>> class B(enum.Flag):
>            b = 3
>            c = 4
>            d = 6
>    >>> B.b | B.c
>    Traceback (most recent call last): ...
>    ValueError: 7 is not a valid B

This part is correct.  If the programmer wants to use actual values instead of auto() then it is on them to do it correctly.  I'd be happy to add a decorator to help ensure all bits have names, but I'm not sure what to call it.

-----------------------------------------------

>    >>> t = B.b | B.c
>    >>> t
>    <B.d|1: 7>

>    >>> ~B.d
>    <B.0: 0>

These parts are not, and will be fixed.

-----------------------------------------------

>    >>> class C(enum.Enum):
>	a = b = enum.auto()	
>    >>> C.a
>    <C.a: 1>
>    >>> C.b
>    <C.b: 2>

Bug, will be fixed.

>    >>> def f():
>            return enum.auto()
>    >>> class E(enum.Enum):
>            a = b = f()
>            c = d = 2
>    >>> E.a is E.b
>    False

Same as above bug, will be fixed

>    >>> E.c is E.d
>    True
>    >>> E.b is E.c
>    True

Same as above bug, will be fixed.  (Had "a" and "b" been given different "auto()"s that last True would be correct as "b" would then have had a value of 2 from auto(), and "c" and "d" also were given values of 2, so all three would have been the same.)

----------
status: closed -> open

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23591>
_______________________________________


More information about the Python-bugs-list mailing list