Ethan Furman added the comment: > All my questions pertain to Flags.
Ah, okay. > You said what to me seem like two contradictory things: > >> Not having 2 named has different consequences for Flag vs IntFlag >> (although *neither is an error*): Flag: no combination of flags will >> ever have the 2 bit set [...] and >> if MyFlags is a Flag then MyFlags(impossible_combination) *will raise an >> exception.* First, let me state the intended use of Flags: primary flags (single-bit flags) will have values of powers of 2: --> class Perm(Flag): ... R = 4 ... W = 2 ... X = 1 ... --> Perm.R | Perm.W | Perm. X <Perm.R|W|X: 7> --> If nicer names are desired for certain combinations (aka secondary flags, or multi-bit), then name them: --> class Perm(Flag): ... ... ... RWX = 7 ... --> Perm.R | Perm.W | Perm.X <Perm.RWX: 7> If, for whatever strange reason, you don't give a certain power of 2 a name, Flag doesn't care: --> class Perm(Flag): ... R = 8 ... W = 4 ... X = 1 ... --> Perm.R | Perm.W | Perm. X <Perm.R|W|X: 13> --> But trying to use that missing value will be an error: --> Perm(6) Traceback (most recent call last): ... ValueError: 6 is not a valid MyFlags This is what I was referring to as "not naming a bit is not an error, but using an impossible value is". What I missed in your example was that, although you hadn't named 2, you still had multi-bit values that included the 2 bit. In other words, in my example there will never be a combination that has the 2 bit set, while in yours (because of your weird values) it is possible. > Are you saying that after I write > > class MyFlags(Flags): > b001 = 1 > b011 = 3 > b100 = 4 > b110 = 6 > > this is _not_ an error, but if after that I call > > print(MyFlags(7)) > > it _is_ an error? No, that's not what I'm saying, and hopefully my explanation above clears that up. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23591> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com