Message274317
> 1) IntFlags is not simply the meet of int and Flags (like IntEnum is the
> meet of int and Enum,
> https://docs.python.org/3.5/library/enum.html#others)?
> It seems a very different class.
No, I think it is. The differences between Enum and IntEnum are entirely because IntEnum members are also ints, so they can do anything an int can do (but they lose their IntEnum-ness when non-Enum operations are performed on them). Similarly, the differences between Flag and IntFlag are entirely because IntFlag members are also ints, so can do whatever ints can do (and, similarly, will lose their IntFlag-ness when non-Flag operations are performed on them).
> 2) (more important) If I give names to 1, 3, 4, and 6, you're in fact
> saying that MyFlags(7) == MyFlags(5) (since 2 is never set)?
(I think you messed up your example, as 4 | 1 == 5 and 6 | 1 == 7 -- 2 is never a factor.)
Absolutely not. 5 != 7, so the two will never be equal no matter which of Flag | IntFlag you are using.
Moreover, if MyFlags is a Flag then MyFlags(impossible_combination) will raise an exception. If MyFlags is an IntFlag then MyFlags(impossible_combination) will have the value of <impossible_combination> and the repr will show all the non-specified bits as base-2 numbers and the specified bits as names. |
|
Date |
User |
Action |
Args |
2016-09-03 17:37:59 | ethan.furman | set | recipients:
+ ethan.furman, barry, rhettinger, vstinner, ezio.melotti, r.david.murray, eli.bendersky, python-dev, martin.panter, serhiy.storchaka, veky |
2016-09-03 17:37:59 | ethan.furman | set | messageid: <1472924279.55.0.351213448028.issue23591@psf.upfronthosting.co.za> |
2016-09-03 17:37:59 | ethan.furman | link | issue23591 messages |
2016-09-03 17:37:59 | ethan.furman | create | |
|