This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author veky
Recipients barry, eli.bendersky, ethan.furman, ezio.melotti, martin.panter, python-dev, r.david.murray, rhettinger, serhiy.storchaka, veky, vstinner
Date 2016-09-04.19:43:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> As a side note, I suspect there would be much less confusion with Flag if we had an AutoEnum.

No, there would be _different_ confusion. :-P

Anyway, let's get back to the discussion. I am quite aware about what's the intended use, but you can't just assume people will know about it. In my view, you must do one of two things:

1) (at least in documentation, and preferably in the code by raising Exceptions at class definition time) forbid the use of Flags whose values are not either a) powers of two, or b) bitwise or of some already declared values


2) Specify and implement a robust algorithm for finding the "cover of bits" for a given numeric value. If the intended algorithm is really "pick the largest member value smaller than given value, subtract and repeat until 0 remains", then it should be said so in the documentation, and preferably some reasons given for the usage of that exact algorithm. ("it was easiest to implement" does not rank very high on my list.)

In other words, MyFlags(7) should either be illegal, or I should be able to interpret what it will be by reading the documentation. Leaving it unspecified is not acceptable IMO.

(In case it isn't clear: I'm for option 1. I _don't_ intend to write MyFlags ever in Python. But if I happen to write it unintentionally (e.g. if I forget to declare 2), I would like Python to tell me I'm doing something wrong.)

(But if you really want option 2 for some reason, that's ok too. I'm just saying I would like it specified, with a rationale if it's not too much of a problem.)
Date User Action Args
2016-09-04 19:43:25vekysetrecipients: + veky, barry, rhettinger, vstinner, ezio.melotti, r.david.murray, eli.bendersky, ethan.furman, python-dev, martin.panter, serhiy.storchaka
2016-09-04 19:43:25vekysetmessageid: <>
2016-09-04 19:43:25vekylinkissue23591 messages
2016-09-04 19:43:25vekycreate